1 /*
2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciMethodData.hpp"
26 #include "ci/ciTypeFlow.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "libadt/dict.hpp"
32 #include "memory/oopFactory.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/instanceMirrorKlass.hpp"
36 #include "oops/objArrayKlass.hpp"
37 #include "oops/typeArrayKlass.hpp"
38 #include "opto/arraycopynode.hpp"
39 #include "opto/callnode.hpp"
40 #include "opto/matcher.hpp"
41 #include "opto/node.hpp"
42 #include "opto/opcodes.hpp"
43 #include "opto/rangeinference.hpp"
44 #include "opto/runtime.hpp"
45 #include "opto/type.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "utilities/checkedCast.hpp"
48 #include "utilities/debug.hpp"
49 #include "utilities/ostream.hpp"
50 #include "utilities/powerOfTwo.hpp"
51 #include "utilities/stringUtils.hpp"
52
53 // Portions of code courtesy of Clifford Click
54
55 // Optimization - Graph Style
56
57 // Dictionary of types shared among compilations.
58 Dict* Type::_shared_type_dict = nullptr;
59
60 // Array which maps compiler types to Basic Types
61 const Type::TypeInfo Type::_type_info[Type::lastype] = {
62 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
63 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
64 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
65 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
66 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
67 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
68 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
69 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
70 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
71 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
72 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
73
74 #if defined(PPC64)
75 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
76 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
77 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
78 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
217 case ciTypeFlow::StateVector::T_NULL:
218 assert(type == ciTypeFlow::StateVector::null_type(), "");
219 return TypePtr::NULL_PTR;
220
221 case ciTypeFlow::StateVector::T_LONG2:
222 // The ciTypeFlow pass pushes a long, then the half.
223 // We do the same.
224 assert(type == ciTypeFlow::StateVector::long2_type(), "");
225 return TypeInt::TOP;
226
227 case ciTypeFlow::StateVector::T_DOUBLE2:
228 // The ciTypeFlow pass pushes double, then the half.
229 // Our convention is the same.
230 assert(type == ciTypeFlow::StateVector::double2_type(), "");
231 return Type::TOP;
232
233 case T_ADDRESS:
234 assert(type->is_return_address(), "");
235 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
236
237 default:
238 // make sure we did not mix up the cases:
239 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
240 assert(type != ciTypeFlow::StateVector::top_type(), "");
241 assert(type != ciTypeFlow::StateVector::null_type(), "");
242 assert(type != ciTypeFlow::StateVector::long2_type(), "");
243 assert(type != ciTypeFlow::StateVector::double2_type(), "");
244 assert(!type->is_return_address(), "");
245
246 return Type::get_const_type(type);
247 }
248 }
249
250
251 //-----------------------make_from_constant------------------------------------
252 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
253 int stable_dimension, bool is_narrow_oop,
254 bool is_autobox_cache) {
255 switch (constant.basic_type()) {
256 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
306 case T_NARROWOOP: loadbt = T_OBJECT; break;
307 case T_ARRAY: loadbt = T_OBJECT; break;
308 case T_ADDRESS: loadbt = T_OBJECT; break;
309 default: break;
310 }
311 if (conbt == loadbt) {
312 if (is_unsigned && conbt == T_BYTE) {
313 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
314 return ciConstant(T_INT, con.as_int() & 0xFF);
315 } else {
316 return con;
317 }
318 }
319 if (conbt == T_SHORT && loadbt == T_CHAR) {
320 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
321 return ciConstant(T_INT, con.as_int() & 0xFFFF);
322 }
323 return ciConstant(); // T_ILLEGAL
324 }
325
326 // Try to constant-fold a stable array element.
327 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
328 BasicType loadbt, bool is_unsigned_load) {
329 // Decode the results of GraphKit::array_element_address.
330 ciConstant element_value = array->element_value_by_offset(off);
331 if (element_value.basic_type() == T_ILLEGAL) {
332 return nullptr; // wrong offset
333 }
334 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
335
336 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
337 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
338
339 if (con.is_valid() && // not a mismatched access
340 !con.is_null_or_zero()) { // not a default value
341 bool is_narrow_oop = (loadbt == T_NARROWOOP);
342 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
343 }
344 return nullptr;
345 }
346
347 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
348 ciField* field;
349 ciType* type = holder->java_mirror_type();
350 if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
351 // Static field
352 field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
353 } else {
354 // Instance field
355 field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
356 }
357 if (field == nullptr) {
358 return nullptr; // Wrong offset
359 }
360 return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
361 }
362
363 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
364 BasicType loadbt, bool is_unsigned_load) {
365 if (!field->is_constant()) {
366 return nullptr; // Non-constant field
539 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
540 ffalse[0] = Type::CONTROL;
541 ffalse[1] = Type::TOP;
542 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
543
544 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
545 fneither[0] = Type::TOP;
546 fneither[1] = Type::TOP;
547 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
548
549 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
550 ftrue[0] = Type::TOP;
551 ftrue[1] = Type::CONTROL;
552 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
553
554 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
555 floop[0] = Type::CONTROL;
556 floop[1] = TypeInt::INT;
557 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
558
559 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
560 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
561 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
562
563 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
564 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
565
566 const Type **fmembar = TypeTuple::fields(0);
567 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
568
569 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
570 fsc[0] = TypeInt::CC;
571 fsc[1] = Type::MEMORY;
572 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
573
574 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
575 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
576 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
577 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
578 false, nullptr, oopDesc::mark_offset_in_bytes());
579 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
580 false, nullptr, oopDesc::klass_offset_in_bytes());
581 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
582
583 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
584
585 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
586 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
587
588 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
589
590 mreg2type[Op_Node] = Type::BOTTOM;
591 mreg2type[Op_Set ] = nullptr;
592 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
593 mreg2type[Op_RegI] = TypeInt::INT;
594 mreg2type[Op_RegP] = TypePtr::BOTTOM;
595 mreg2type[Op_RegF] = Type::FLOAT;
596 mreg2type[Op_RegD] = Type::DOUBLE;
597 mreg2type[Op_RegL] = TypeLong::LONG;
598 mreg2type[Op_RegFlags] = TypeInt::CC;
599
600 GrowableArray<ciInstanceKlass*> array_interfaces;
601 array_interfaces.push(current->env()->Cloneable_klass());
602 array_interfaces.push(current->env()->Serializable_klass());
603 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
604 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
605
606 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS), nullptr, false, Type::OffsetBot);
607 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
608
609 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
610
611 #ifdef _LP64
612 if (UseCompressedOops) {
613 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
614 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
615 } else
616 #endif
617 {
618 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
619 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
620 }
621 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
622 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
623 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
624 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
625 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
626 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
627 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
628
629 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
630 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
631 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
632 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
633 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
634 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
635 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
636 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
637 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
638 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
639 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
640 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
641
642 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
643 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
644
645 const Type **fi2c = TypeTuple::fields(2);
646 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
647 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
648 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
649
650 const Type **intpair = TypeTuple::fields(2);
651 intpair[0] = TypeInt::INT;
652 intpair[1] = TypeInt::INT;
653 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
654
655 const Type **longpair = TypeTuple::fields(2);
656 longpair[0] = TypeLong::LONG;
657 longpair[1] = TypeLong::LONG;
658 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
659
660 const Type **intccpair = TypeTuple::fields(2);
661 intccpair[0] = TypeInt::INT;
662 intccpair[1] = TypeInt::CC;
663 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
664
665 const Type **longccpair = TypeTuple::fields(2);
666 longccpair[0] = TypeLong::LONG;
667 longccpair[1] = TypeInt::CC;
668 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
669
670 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
671 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
672 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
673 _const_basic_type[T_CHAR] = TypeInt::CHAR;
674 _const_basic_type[T_BYTE] = TypeInt::BYTE;
675 _const_basic_type[T_SHORT] = TypeInt::SHORT;
676 _const_basic_type[T_INT] = TypeInt::INT;
677 _const_basic_type[T_LONG] = TypeLong::LONG;
678 _const_basic_type[T_FLOAT] = Type::FLOAT;
679 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
680 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
681 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
682 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
683 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
684 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
685
686 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
687 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
688 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
689 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
690 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
691 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
692 _zero_type[T_INT] = TypeInt::ZERO;
693 _zero_type[T_LONG] = TypeLong::ZERO;
694 _zero_type[T_FLOAT] = TypeF::ZERO;
695 _zero_type[T_DOUBLE] = TypeD::ZERO;
696 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
697 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
698 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
699 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
700
701 // get_zero_type() should not happen for T_CONFLICT
702 _zero_type[T_CONFLICT]= nullptr;
703
704 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
705 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
706
707 if (Matcher::supports_scalable_vector()) {
708 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
709 }
710
711 // Vector predefined types, it needs initialized _const_basic_type[].
712 if (Matcher::vector_size_supported(T_BYTE, 4)) {
713 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
714 }
715 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
716 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
717 }
952 ~VerifyMeet() {
953 assert(_C->_type_verify->_depth != 0, "");
954 _C->_type_verify->_depth--;
955 if (_C->_type_verify->_depth == 0) {
956 _C->_type_verify->_cache.trunc_to(0);
957 }
958 }
959
960 const Type* meet(const Type* t1, const Type* t2) const {
961 return _C->_type_verify->meet(t1, t2);
962 }
963
964 void add(const Type* t1, const Type* t2, const Type* res) const {
965 _C->_type_verify->add(t1, t2, res);
966 }
967 };
968
969 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
970 Compile* C = Compile::current();
971 const Type* mt2 = verify.meet(t, this);
972 if (mt != mt2) {
973 tty->print_cr("=== Meet Not Commutative ===");
974 tty->print("t = "); t->dump(); tty->cr();
975 tty->print("this = "); dump(); tty->cr();
976 tty->print("t meet this = "); mt2->dump(); tty->cr();
977 tty->print("this meet t = "); mt->dump(); tty->cr();
978 fatal("meet not commutative");
979 }
980 const Type* dual_join = mt->_dual;
981 const Type* t2t = verify.meet(dual_join,t->_dual);
982 const Type* t2this = verify.meet(dual_join,this->_dual);
983
984 // Interface meet Oop is Not Symmetric:
985 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
986 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
987
988 if (t2t != t->_dual || t2this != this->_dual) {
989 tty->print_cr("=== Meet Not Symmetric ===");
990 tty->print("t = "); t->dump(); tty->cr();
991 tty->print("this= "); dump(); tty->cr();
992 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
993
994 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
995 tty->print("this_dual= "); _dual->dump(); tty->cr();
996 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
997
998 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
999 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1000
1001 fatal("meet not symmetric");
1002 }
1003 }
1004 #endif
1005
1006 //------------------------------meet-------------------------------------------
1007 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1008 // commutative and the lattice is symmetric.
1009 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1010 if (isa_narrowoop() && t->isa_narrowoop()) {
1011 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1012 return result->make_narrowoop();
1013 }
1014 if (isa_narrowklass() && t->isa_narrowklass()) {
1015 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1016 return result->make_narrowklass();
1017 }
1018
1019 #ifdef ASSERT
1020 Compile* C = Compile::current();
1021 VerifyMeet verify(C);
1022 #endif
1023
1024 const Type *this_t = maybe_remove_speculative(include_speculative);
1025 t = t->maybe_remove_speculative(include_speculative);
1026
1027 const Type *mt = this_t->xmeet(t);
1028 #ifdef ASSERT
1029 verify.add(this_t, t, mt);
1030 if (isa_narrowoop() || t->isa_narrowoop()) {
1031 return mt;
1032 }
1033 if (isa_narrowklass() || t->isa_narrowklass()) {
1034 return mt;
1035 }
1036 this_t->check_symmetrical(t, mt, verify);
1037 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1038 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1039 #endif
1040 return mt;
1041 }
1042
1043 //------------------------------xmeet------------------------------------------
1044 // Compute the MEET of two types. It returns a new Type object.
1045 const Type *Type::xmeet( const Type *t ) const {
1046 // Perform a fast test for common case; meeting the same types together.
1047 if( this == t ) return this; // Meeting same type-rep?
1048
1049 // Meeting TOP with anything?
1050 if( _base == Top ) return t;
1051
1052 // Meeting BOTTOM with anything?
1053 if( _base == Bottom ) return BOTTOM;
1054
1055 // Current "this->_base" is one of: Bad, Multi, Control, Top,
2032 void TypeLong::dump_verbose() const {
2033 TypeIntHelper::int_type_dump(this, tty, true);
2034 }
2035 #endif
2036
2037 //=============================================================================
2038 // Convenience common pre-built types.
2039 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2040 const TypeTuple *TypeTuple::IFFALSE;
2041 const TypeTuple *TypeTuple::IFTRUE;
2042 const TypeTuple *TypeTuple::IFNEITHER;
2043 const TypeTuple *TypeTuple::LOOPBODY;
2044 const TypeTuple *TypeTuple::MEMBAR;
2045 const TypeTuple *TypeTuple::STORECONDITIONAL;
2046 const TypeTuple *TypeTuple::START_I2C;
2047 const TypeTuple *TypeTuple::INT_PAIR;
2048 const TypeTuple *TypeTuple::LONG_PAIR;
2049 const TypeTuple *TypeTuple::INT_CC_PAIR;
2050 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2051
2052 //------------------------------make-------------------------------------------
2053 // Make a TypeTuple from the range of a method signature
2054 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2055 ciType* return_type = sig->return_type();
2056 uint arg_cnt = return_type->size();
2057 const Type **field_array = fields(arg_cnt);
2058 switch (return_type->basic_type()) {
2059 case T_LONG:
2060 field_array[TypeFunc::Parms] = TypeLong::LONG;
2061 field_array[TypeFunc::Parms+1] = Type::HALF;
2062 break;
2063 case T_DOUBLE:
2064 field_array[TypeFunc::Parms] = Type::DOUBLE;
2065 field_array[TypeFunc::Parms+1] = Type::HALF;
2066 break;
2067 case T_OBJECT:
2068 case T_ARRAY:
2069 case T_BOOLEAN:
2070 case T_CHAR:
2071 case T_FLOAT:
2072 case T_BYTE:
2073 case T_SHORT:
2074 case T_INT:
2075 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2076 break;
2077 case T_VOID:
2078 break;
2079 default:
2080 ShouldNotReachHere();
2081 }
2082 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2083 }
2084
2085 // Make a TypeTuple from the domain of a method signature
2086 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2087 uint arg_cnt = sig->size();
2088
2089 uint pos = TypeFunc::Parms;
2090 const Type **field_array;
2091 if (recv != nullptr) {
2092 arg_cnt++;
2093 field_array = fields(arg_cnt);
2094 // Use get_const_type here because it respects UseUniqueSubclasses:
2095 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2096 } else {
2097 field_array = fields(arg_cnt);
2098 }
2099
2100 int i = 0;
2101 while (pos < TypeFunc::Parms + arg_cnt) {
2102 ciType* type = sig->type_at(i);
2103
2104 switch (type->basic_type()) {
2105 case T_LONG:
2106 field_array[pos++] = TypeLong::LONG;
2107 field_array[pos++] = Type::HALF;
2108 break;
2109 case T_DOUBLE:
2110 field_array[pos++] = Type::DOUBLE;
2111 field_array[pos++] = Type::HALF;
2112 break;
2113 case T_OBJECT:
2114 case T_ARRAY:
2115 case T_FLOAT:
2116 case T_INT:
2117 field_array[pos++] = get_const_type(type, interface_handling);
2118 break;
2119 case T_BOOLEAN:
2120 case T_CHAR:
2121 case T_BYTE:
2122 case T_SHORT:
2123 field_array[pos++] = TypeInt::INT;
2124 break;
2125 default:
2126 ShouldNotReachHere();
2127 }
2128 i++;
2129 }
2130
2131 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2132 }
2133
2134 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2135 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2136 }
2137
2138 //------------------------------fields-----------------------------------------
2139 // Subroutine call type with space allocated for argument types
2140 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2141 const Type **TypeTuple::fields( uint arg_cnt ) {
2142 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2143 flds[TypeFunc::Control ] = Type::CONTROL;
2144 flds[TypeFunc::I_O ] = Type::ABIO;
2145 flds[TypeFunc::Memory ] = Type::MEMORY;
2146 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2147 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2148
2149 return flds;
2244 if (_fields[i]->empty()) return true;
2245 }
2246 return false;
2247 }
2248
2249 //=============================================================================
2250 // Convenience common pre-built types.
2251
2252 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2253 // Certain normalizations keep us sane when comparing types.
2254 // We do not want arrayOop variables to differ only by the wideness
2255 // of their index types. Pick minimum wideness, since that is the
2256 // forced wideness of small ranges anyway.
2257 if (size->_widen != Type::WidenMin)
2258 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2259 else
2260 return size;
2261 }
2262
2263 //------------------------------make-------------------------------------------
2264 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2265 if (UseCompressedOops && elem->isa_oopptr()) {
2266 elem = elem->make_narrowoop();
2267 }
2268 size = normalize_array_size(size);
2269 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2270 }
2271
2272 //------------------------------meet-------------------------------------------
2273 // Compute the MEET of two types. It returns a new Type object.
2274 const Type *TypeAry::xmeet( const Type *t ) const {
2275 // Perform a fast test for common case; meeting the same types together.
2276 if( this == t ) return this; // Meeting same type-rep?
2277
2278 // Current "this->_base" is Ary
2279 switch (t->base()) { // switch on original type
2280
2281 case Bottom: // Ye Olde Default
2282 return t;
2283
2284 default: // All else is a mistake
2285 typerr(t);
2286
2287 case Array: { // Meeting 2 arrays?
2288 const TypeAry* a = t->is_ary();
2289 const Type* size = _size->xmeet(a->_size);
2290 const TypeInt* isize = size->isa_int();
2291 if (isize == nullptr) {
2292 assert(size == Type::TOP || size == Type::BOTTOM, "");
2293 return size;
2294 }
2295 return TypeAry::make(_elem->meet_speculative(a->_elem),
2296 isize, _stable && a->_stable);
2297 }
2298 case Top:
2299 break;
2300 }
2301 return this; // Return the double constant
2302 }
2303
2304 //------------------------------xdual------------------------------------------
2305 // Dual: compute field-by-field dual
2306 const Type *TypeAry::xdual() const {
2307 const TypeInt* size_dual = _size->dual()->is_int();
2308 size_dual = normalize_array_size(size_dual);
2309 return new TypeAry(_elem->dual(), size_dual, !_stable);
2310 }
2311
2312 //------------------------------eq---------------------------------------------
2313 // Structural equality check for Type representations
2314 bool TypeAry::eq( const Type *t ) const {
2315 const TypeAry *a = (const TypeAry*)t;
2316 return _elem == a->_elem &&
2317 _stable == a->_stable &&
2318 _size == a->_size;
2319 }
2320
2321 //------------------------------hash-------------------------------------------
2322 // Type-specific hashing function.
2323 uint TypeAry::hash(void) const {
2324 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);
2325 }
2326
2327 /**
2328 * Return same type without a speculative part in the element
2329 */
2330 const TypeAry* TypeAry::remove_speculative() const {
2331 return make(_elem->remove_speculative(), _size, _stable);
2332 }
2333
2334 /**
2335 * Return same type with cleaned up speculative part of element
2336 */
2337 const Type* TypeAry::cleanup_speculative() const {
2338 return make(_elem->cleanup_speculative(), _size, _stable);
2339 }
2340
2341 /**
2342 * Return same type but with a different inline depth (used for speculation)
2343 *
2344 * @param depth depth to meet with
2345 */
2346 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2347 if (!UseInlineDepthForSpeculativeTypes) {
2348 return this;
2349 }
2350 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2351 }
2352
2353 //------------------------------dump2------------------------------------------
2354 #ifndef PRODUCT
2355 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2356 if (_stable) st->print("stable:");
2357 _elem->dump2(d, depth, st);
2358 st->print("[");
2359 _size->dump2(d, depth, st);
2360 st->print("]");
2361 }
2362 #endif
2363
2364 //------------------------------singleton--------------------------------------
2365 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2366 // constants (Ldi nodes). Singletons are integer, float or double constants
2367 // or a single symbol.
2368 bool TypeAry::singleton(void) const {
2369 return false; // Never a singleton
2370 }
2371
2372 bool TypeAry::empty(void) const {
2373 return _elem->empty() || _size->empty();
2374 }
2375
2376 //--------------------------ary_must_be_exact----------------------------------
2377 bool TypeAry::ary_must_be_exact() const {
2378 // This logic looks at the element type of an array, and returns true
2379 // if the element type is either a primitive or a final instance class.
2380 // In such cases, an array built on this ary must have no subclasses.
2381 if (_elem == BOTTOM) return false; // general array not exact
2382 if (_elem == TOP ) return false; // inverted general array not exact
2383 const TypeOopPtr* toop = nullptr;
2384 if (UseCompressedOops && _elem->isa_narrowoop()) {
2385 toop = _elem->make_ptr()->isa_oopptr();
2386 } else {
2387 toop = _elem->isa_oopptr();
2388 }
2389 if (!toop) return true; // a primitive type, like int
2390 if (!toop->is_loaded()) return false; // unloaded class
2391 const TypeInstPtr* tinst;
2392 if (_elem->isa_narrowoop())
2393 tinst = _elem->make_ptr()->isa_instptr();
2394 else
2395 tinst = _elem->isa_instptr();
2396 if (tinst)
2397 return tinst->instance_klass()->is_final();
2398 const TypeAryPtr* tap;
2399 if (_elem->isa_narrowoop())
2400 tap = _elem->make_ptr()->isa_aryptr();
2401 else
2402 tap = _elem->isa_aryptr();
2403 if (tap)
2404 return tap->ary()->ary_must_be_exact();
2405 return false;
2406 }
2407
2408 //==============================TypeVect=======================================
2409 // Convenience common pre-built types.
2410 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2411 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2412 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2413 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2414 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2415 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2416 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2417
2552
2553 //=============================================================================
2554 // Convenience common pre-built types.
2555 const TypePtr *TypePtr::NULL_PTR;
2556 const TypePtr *TypePtr::NOTNULL;
2557 const TypePtr *TypePtr::BOTTOM;
2558
2559 //------------------------------meet-------------------------------------------
2560 // Meet over the PTR enum
2561 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2562 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2563 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2564 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2565 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2566 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2567 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2568 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2569 };
2570
2571 //------------------------------make-------------------------------------------
2572 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2573 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2574 }
2575
2576 //------------------------------cast_to_ptr_type-------------------------------
2577 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2578 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2579 if( ptr == _ptr ) return this;
2580 return make(_base, ptr, _offset, _speculative, _inline_depth);
2581 }
2582
2583 //------------------------------get_con----------------------------------------
2584 intptr_t TypePtr::get_con() const {
2585 assert( _ptr == Null, "" );
2586 return _offset;
2587 }
2588
2589 //------------------------------meet-------------------------------------------
2590 // Compute the MEET of two types. It returns a new Type object.
2591 const Type *TypePtr::xmeet(const Type *t) const {
2592 const Type* res = xmeet_helper(t);
2593 if (res->isa_ptr() == nullptr) {
2594 return res;
2595 }
2596
2597 const TypePtr* res_ptr = res->is_ptr();
2598 if (res_ptr->speculative() != nullptr) {
2599 // type->speculative() is null means that speculation is no better
2600 // than type, i.e. type->speculative() == type. So there are 2
2601 // ways to represent the fact that we have no useful speculative
2602 // data and we should use a single one to be able to test for
2603 // equality between types. Check whether type->speculative() ==
2604 // type and set speculative to null if it is the case.
2605 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2606 return res_ptr->remove_speculative();
2640 int depth = meet_inline_depth(tp->inline_depth());
2641 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2642 }
2643 case RawPtr: // For these, flip the call around to cut down
2644 case OopPtr:
2645 case InstPtr: // on the cases I have to handle.
2646 case AryPtr:
2647 case MetadataPtr:
2648 case KlassPtr:
2649 case InstKlassPtr:
2650 case AryKlassPtr:
2651 return t->xmeet(this); // Call in reverse direction
2652 default: // All else is a mistake
2653 typerr(t);
2654
2655 }
2656 return this;
2657 }
2658
2659 //------------------------------meet_offset------------------------------------
2660 int TypePtr::meet_offset( int offset ) const {
2661 // Either is 'TOP' offset? Return the other offset!
2662 if( _offset == OffsetTop ) return offset;
2663 if( offset == OffsetTop ) return _offset;
2664 // If either is different, return 'BOTTOM' offset
2665 if( _offset != offset ) return OffsetBot;
2666 return _offset;
2667 }
2668
2669 //------------------------------dual_offset------------------------------------
2670 int TypePtr::dual_offset( ) const {
2671 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2672 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2673 return _offset; // Map everything else into self
2674 }
2675
2676 //------------------------------xdual------------------------------------------
2677 // Dual: compute field-by-field dual
2678 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2679 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2680 };
2681 const Type *TypePtr::xdual() const {
2682 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2683 }
2684
2685 //------------------------------xadd_offset------------------------------------
2686 int TypePtr::xadd_offset( intptr_t offset ) const {
2687 // Adding to 'TOP' offset? Return 'TOP'!
2688 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2689 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2690 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2691 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2692 offset += (intptr_t)_offset;
2693 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2694
2695 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2696 // It is possible to construct a negative offset during PhaseCCP
2697
2698 return (int)offset; // Sum valid offsets
2699 }
2700
2701 //------------------------------add_offset-------------------------------------
2702 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2703 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2704 }
2705
2706 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2707 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2708 }
2709
2710 //------------------------------eq---------------------------------------------
2711 // Structural equality check for Type representations
2712 bool TypePtr::eq( const Type *t ) const {
2713 const TypePtr *a = (const TypePtr*)t;
2714 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2715 }
2716
2717 //------------------------------hash-------------------------------------------
2718 // Type-specific hashing function.
2719 uint TypePtr::hash(void) const {
2720 return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2721 }
2722
2723 /**
2724 * Return same type without a speculative part
2725 */
2726 const TypePtr* TypePtr::remove_speculative() const {
2727 if (_speculative == nullptr) {
2728 return this;
2729 }
2730 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2731 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2732 }
2733
2734 /**
2735 * Return same type but drop speculative part if we know we won't use
2736 * it
2737 */
2738 const Type* TypePtr::cleanup_speculative() const {
2739 if (speculative() == nullptr) {
2740 return this;
2957 return false;
2958 }
2959 // We already know the speculative type cannot be null
2960 if (!speculative_maybe_null()) {
2961 return false;
2962 }
2963 // We already know this is always null
2964 if (this == TypePtr::NULL_PTR) {
2965 return false;
2966 }
2967 // We already know the speculative type is always null
2968 if (speculative_always_null()) {
2969 return false;
2970 }
2971 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
2972 return false;
2973 }
2974 return true;
2975 }
2976
2977 //------------------------------dump2------------------------------------------
2978 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2979 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
2980 };
2981
2982 #ifndef PRODUCT
2983 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2984 st->print("ptr:%s", ptr_msg[_ptr]);
2985 dump_offset(st);
2986 dump_inline_depth(st);
2987 dump_speculative(st);
2988 }
2989
2990 void TypePtr::dump_offset(outputStream* st) const {
2991 if (_offset == OffsetBot) {
2992 st->print("+bot");
2993 } else if (_offset == OffsetTop) {
2994 st->print("+top");
2995 } else {
2996 st->print("+%d", _offset);
2997 }
2998 }
2999
3000 /**
3001 *dump the speculative part of the type
3002 */
3003 void TypePtr::dump_speculative(outputStream *st) const {
3004 if (_speculative != nullptr) {
3005 st->print(" (speculative=");
3006 _speculative->dump_on(st);
3007 st->print(")");
3008 }
3009 }
3010
3011 /**
3012 *dump the inline depth of the type
3013 */
3014 void TypePtr::dump_inline_depth(outputStream *st) const {
3015 if (_inline_depth != InlineDepthBottom) {
3016 if (_inline_depth == InlineDepthTop) {
3017 st->print(" (inline_depth=InlineDepthTop)");
3018 } else {
3019 st->print(" (inline_depth=%d)", _inline_depth);
3020 }
3021 }
3022 }
3023 #endif
3024
3025 //------------------------------singleton--------------------------------------
3026 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3027 // constants
3028 bool TypePtr::singleton(void) const {
3029 // TopPTR, Null, AnyNull, Constant are all singletons
3030 return (_offset != OffsetBot) && !below_centerline(_ptr);
3031 }
3032
3033 bool TypePtr::empty(void) const {
3034 return (_offset == OffsetTop) || above_centerline(_ptr);
3035 }
3036
3037 //=============================================================================
3038 // Convenience common pre-built types.
3039 const TypeRawPtr *TypeRawPtr::BOTTOM;
3040 const TypeRawPtr *TypeRawPtr::NOTNULL;
3041
3042 //------------------------------make-------------------------------------------
3043 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3044 assert( ptr != Constant, "what is the constant?" );
3045 assert( ptr != Null, "Use TypePtr for null" );
3046 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3047 }
3048
3049 const TypeRawPtr *TypeRawPtr::make(address bits) {
3050 assert(bits != nullptr, "Use TypePtr for null");
3051 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3052 }
3053
3054 //------------------------------cast_to_ptr_type-------------------------------
3422 #endif
3423
3424 // Can't be implemented because there's no way to know if the type is above or below the center line.
3425 const Type* TypeInterfaces::xmeet(const Type* t) const {
3426 ShouldNotReachHere();
3427 return Type::xmeet(t);
3428 }
3429
3430 bool TypeInterfaces::singleton(void) const {
3431 ShouldNotReachHere();
3432 return Type::singleton();
3433 }
3434
3435 bool TypeInterfaces::has_non_array_interface() const {
3436 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3437
3438 return !TypeAryPtr::_array_interfaces->contains(this);
3439 }
3440
3441 //------------------------------TypeOopPtr-------------------------------------
3442 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3443 int instance_id, const TypePtr* speculative, int inline_depth)
3444 : TypePtr(t, ptr, offset, speculative, inline_depth),
3445 _const_oop(o), _klass(k),
3446 _interfaces(interfaces),
3447 _klass_is_exact(xk),
3448 _is_ptr_to_narrowoop(false),
3449 _is_ptr_to_narrowklass(false),
3450 _is_ptr_to_boxed_value(false),
3451 _instance_id(instance_id) {
3452 #ifdef ASSERT
3453 if (klass() != nullptr && klass()->is_loaded()) {
3454 interfaces->verify_is_loaded();
3455 }
3456 #endif
3457 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3458 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3459 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3460 }
3461 #ifdef _LP64
3462 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3463 if (_offset == oopDesc::klass_offset_in_bytes()) {
3464 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3465 } else if (klass() == nullptr) {
3466 // Array with unknown body type
3467 assert(this->isa_aryptr(), "only arrays without klass");
3468 _is_ptr_to_narrowoop = UseCompressedOops;
3469 } else if (this->isa_aryptr()) {
3470 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3471 _offset != arrayOopDesc::length_offset_in_bytes());
3472 } else if (klass()->is_instance_klass()) {
3473 ciInstanceKlass* ik = klass()->as_instance_klass();
3474 if (this->isa_klassptr()) {
3475 // Perm objects don't use compressed references
3476 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3477 // unsafe access
3478 _is_ptr_to_narrowoop = UseCompressedOops;
3479 } else {
3480 assert(this->isa_instptr(), "must be an instance ptr.");
3481
3482 if (klass() == ciEnv::current()->Class_klass() &&
3483 (_offset == java_lang_Class::klass_offset() ||
3484 _offset == java_lang_Class::array_klass_offset())) {
3485 // Special hidden fields from the Class.
3486 assert(this->isa_instptr(), "must be an instance ptr.");
3487 _is_ptr_to_narrowoop = false;
3488 } else if (klass() == ciEnv::current()->Class_klass() &&
3489 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3490 // Static fields
3491 BasicType basic_elem_type = T_ILLEGAL;
3492 if (const_oop() != nullptr) {
3493 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3494 basic_elem_type = k->get_field_type_by_offset(_offset, true);
3495 }
3496 if (basic_elem_type != T_ILLEGAL) {
3497 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3498 } else {
3499 // unsafe access
3500 _is_ptr_to_narrowoop = UseCompressedOops;
3501 }
3502 } else {
3503 // Instance fields which contains a compressed oop references.
3504 BasicType basic_elem_type = ik->get_field_type_by_offset(_offset, false);
3505 if (basic_elem_type != T_ILLEGAL) {
3506 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3507 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3508 // Compile::find_alias_type() cast exactness on all types to verify
3509 // that it does not affect alias type.
3510 _is_ptr_to_narrowoop = UseCompressedOops;
3511 } else {
3512 // Type for the copy start in LibraryCallKit::inline_native_clone().
3513 _is_ptr_to_narrowoop = UseCompressedOops;
3514 }
3515 }
3516 }
3517 }
3518 }
3519 #endif
3520 }
3521
3522 //------------------------------make-------------------------------------------
3523 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3524 const TypePtr* speculative, int inline_depth) {
3525 assert(ptr != Constant, "no constant generic pointers");
3526 ciKlass* k = Compile::current()->env()->Object_klass();
3527 bool xk = false;
3528 ciObject* o = nullptr;
3529 const TypeInterfaces* interfaces = TypeInterfaces::make();
3530 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3531 }
3532
3533
3534 //------------------------------cast_to_ptr_type-------------------------------
3535 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3536 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3537 if( ptr == _ptr ) return this;
3538 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3539 }
3540
3541 //-----------------------------cast_to_instance_id----------------------------
3542 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3543 // There are no instances of a general oop.
3544 // Return self unchanged.
3545 return this;
3546 }
3547
3548 //-----------------------------cast_to_exactness-------------------------------
3549 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3550 // There is no such thing as an exact general oop.
3551 // Return self unchanged.
3552 return this;
3553 }
3554
3555
3556 //------------------------------as_klass_type----------------------------------
3557 // Return the klass type corresponding to this instance or array type.
3558 // It is the type that is loaded from an object of this type.
3559 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3560 ShouldNotReachHere();
3561 return nullptr;
3562 }
3563
3564 //------------------------------meet-------------------------------------------
3565 // Compute the MEET of two types. It returns a new Type object.
3566 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3567 // Perform a fast test for common case; meeting the same types together.
3568 if( this == t ) return this; // Meeting same type-rep?
3569
3570 // Current "this->_base" is OopPtr
3571 switch (t->base()) { // switch on original type
3572
3573 case Int: // Mixing ints & oops happens when javac
3574 case Long: // reuses local variables
3575 case HalfFloatTop:
3584 case NarrowOop:
3585 case NarrowKlass:
3586 case Bottom: // Ye Olde Default
3587 return Type::BOTTOM;
3588 case Top:
3589 return this;
3590
3591 default: // All else is a mistake
3592 typerr(t);
3593
3594 case RawPtr:
3595 case MetadataPtr:
3596 case KlassPtr:
3597 case InstKlassPtr:
3598 case AryKlassPtr:
3599 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3600
3601 case AnyPtr: {
3602 // Found an AnyPtr type vs self-OopPtr type
3603 const TypePtr *tp = t->is_ptr();
3604 int offset = meet_offset(tp->offset());
3605 PTR ptr = meet_ptr(tp->ptr());
3606 const TypePtr* speculative = xmeet_speculative(tp);
3607 int depth = meet_inline_depth(tp->inline_depth());
3608 switch (tp->ptr()) {
3609 case Null:
3610 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3611 // else fall through:
3612 case TopPTR:
3613 case AnyNull: {
3614 int instance_id = meet_instance_id(InstanceTop);
3615 return make(ptr, offset, instance_id, speculative, depth);
3616 }
3617 case BotPTR:
3618 case NotNull:
3619 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3620 default: typerr(t);
3621 }
3622 }
3623
3624 case OopPtr: { // Meeting to other OopPtrs
3626 int instance_id = meet_instance_id(tp->instance_id());
3627 const TypePtr* speculative = xmeet_speculative(tp);
3628 int depth = meet_inline_depth(tp->inline_depth());
3629 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3630 }
3631
3632 case InstPtr: // For these, flip the call around to cut down
3633 case AryPtr:
3634 return t->xmeet(this); // Call in reverse direction
3635
3636 } // End of switch
3637 return this; // Return the double constant
3638 }
3639
3640
3641 //------------------------------xdual------------------------------------------
3642 // Dual of a pure heap pointer. No relevant klass or oop information.
3643 const Type *TypeOopPtr::xdual() const {
3644 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3645 assert(const_oop() == nullptr, "no constants here");
3646 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3647 }
3648
3649 //--------------------------make_from_klass_common-----------------------------
3650 // Computes the element-type given a klass.
3651 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3652 if (klass->is_instance_klass()) {
3653 Compile* C = Compile::current();
3654 Dependencies* deps = C->dependencies();
3655 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3656 // Element is an instance
3657 bool klass_is_exact = false;
3658 if (klass->is_loaded()) {
3659 // Try to set klass_is_exact.
3660 ciInstanceKlass* ik = klass->as_instance_klass();
3661 klass_is_exact = ik->is_final();
3662 if (!klass_is_exact && klass_change
3663 && deps != nullptr && UseUniqueSubclasses) {
3664 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3665 if (sub != nullptr) {
3666 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3667 klass = ik = sub;
3668 klass_is_exact = sub->is_final();
3669 }
3670 }
3671 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3672 !ik->is_interface() && !ik->has_subklass()) {
3673 // Add a dependence; if concrete subclass added we need to recompile
3674 deps->assert_leaf_type(ik);
3675 klass_is_exact = true;
3676 }
3677 }
3678 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3679 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3680 } else if (klass->is_obj_array_klass()) {
3681 // Element is an object array. Recursively call ourself.
3682 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3683 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3684 bool xk = etype->klass_is_exact();
3685 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3686 // We used to pass NotNull in here, asserting that the sub-arrays
3687 // are all not-null. This is not true in generally, as code can
3688 // slam nulls down in the subarrays.
3689 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3690 return arr;
3691 } else if (klass->is_type_array_klass()) {
3692 // Element is an typeArray
3693 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3694 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3695 // We used to pass NotNull in here, asserting that the array pointer
3696 // is not-null. That was not true in general.
3697 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3698 return arr;
3699 } else {
3700 ShouldNotReachHere();
3701 return nullptr;
3702 }
3703 }
3704
3705 //------------------------------make_from_constant-----------------------------
3706 // Make a java pointer from an oop constant
3707 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3708 assert(!o->is_null_object(), "null object not yet handled here.");
3709
3710 const bool make_constant = require_constant || o->should_be_constant();
3711
3712 ciKlass* klass = o->klass();
3713 if (klass->is_instance_klass()) {
3714 // Element is an instance
3715 if (make_constant) {
3716 return TypeInstPtr::make(o);
3717 } else {
3718 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3719 }
3720 } else if (klass->is_obj_array_klass()) {
3721 // Element is an object array. Recursively call ourself.
3722 const TypeOopPtr *etype =
3723 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3724 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3725 // We used to pass NotNull in here, asserting that the sub-arrays
3726 // are all not-null. This is not true in generally, as code can
3727 // slam nulls down in the subarrays.
3728 if (make_constant) {
3729 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3730 } else {
3731 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3732 }
3733 } else if (klass->is_type_array_klass()) {
3734 // Element is an typeArray
3735 const Type* etype =
3736 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3737 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3738 // We used to pass NotNull in here, asserting that the array pointer
3739 // is not-null. That was not true in general.
3740 if (make_constant) {
3741 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3742 } else {
3743 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3744 }
3745 }
3746
3747 fatal("unhandled object type");
3748 return nullptr;
3749 }
3750
3751 //------------------------------get_con----------------------------------------
3752 intptr_t TypeOopPtr::get_con() const {
3753 assert( _ptr == Null || _ptr == Constant, "" );
3754 assert( _offset >= 0, "" );
3755
3756 if (_offset != 0) {
3757 // After being ported to the compiler interface, the compiler no longer
3758 // directly manipulates the addresses of oops. Rather, it only has a pointer
3759 // to a handle at compile time. This handle is embedded in the generated
3760 // code and dereferenced at the time the nmethod is made. Until that time,
3761 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3762 // have access to the addresses!). This does not seem to currently happen,
3763 // but this assertion here is to help prevent its occurrence.
3764 tty->print_cr("Found oop constant with non-zero offset");
3765 ShouldNotReachHere();
3766 }
3767
3768 return (intptr_t)const_oop()->constant_encoding();
3769 }
3770
3771
3772 //-----------------------------filter------------------------------------------
3773 // Do not allow interface-vs.-noninterface joins to collapse to top.
3774 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3775
3776 const Type* ft = join_helper(kills, include_speculative);
3822 dump_speculative(st);
3823 }
3824
3825 void TypeOopPtr::dump_instance_id(outputStream* st) const {
3826 if (_instance_id == InstanceTop) {
3827 st->print(",iid=top");
3828 } else if (_instance_id == InstanceBot) {
3829 st->print(",iid=bot");
3830 } else {
3831 st->print(",iid=%d", _instance_id);
3832 }
3833 }
3834 #endif
3835
3836 //------------------------------singleton--------------------------------------
3837 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3838 // constants
3839 bool TypeOopPtr::singleton(void) const {
3840 // detune optimizer to not generate constant oop + constant offset as a constant!
3841 // TopPTR, Null, AnyNull, Constant are all singletons
3842 return (_offset == 0) && !below_centerline(_ptr);
3843 }
3844
3845 //------------------------------add_offset-------------------------------------
3846 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3847 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3848 }
3849
3850 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3851 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3852 }
3853
3854 /**
3855 * Return same type without a speculative part
3856 */
3857 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3858 if (_speculative == nullptr) {
3859 return this;
3860 }
3861 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3862 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3863 }
3864
3865 /**
3866 * Return same type but drop speculative part if we know we won't use
3867 * it
3868 */
3869 const Type* TypeOopPtr::cleanup_speculative() const {
3870 // If the klass is exact and the ptr is not null then there's
3871 // nothing that the speculative type can help us with
3944 const TypeInstPtr *TypeInstPtr::BOTTOM;
3945 const TypeInstPtr *TypeInstPtr::MIRROR;
3946 const TypeInstPtr *TypeInstPtr::MARK;
3947 const TypeInstPtr *TypeInstPtr::KLASS;
3948
3949 // Is there a single ciKlass* that can represent that type?
3950 ciKlass* TypeInstPtr::exact_klass_helper() const {
3951 if (_interfaces->empty()) {
3952 return _klass;
3953 }
3954 if (_klass != ciEnv::current()->Object_klass()) {
3955 if (_interfaces->eq(_klass->as_instance_klass())) {
3956 return _klass;
3957 }
3958 return nullptr;
3959 }
3960 return _interfaces->exact_klass();
3961 }
3962
3963 //------------------------------TypeInstPtr-------------------------------------
3964 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
3965 int instance_id, const TypePtr* speculative, int inline_depth)
3966 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
3967 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
3968 assert(k != nullptr &&
3969 (k->is_loaded() || o == nullptr),
3970 "cannot have constants with non-loaded klass");
3971 };
3972
3973 //------------------------------make-------------------------------------------
3974 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3975 ciKlass* k,
3976 const TypeInterfaces* interfaces,
3977 bool xk,
3978 ciObject* o,
3979 int offset,
3980 int instance_id,
3981 const TypePtr* speculative,
3982 int inline_depth) {
3983 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3984 // Either const_oop() is null or else ptr is Constant
3985 assert( (!o && ptr != Constant) || (o && ptr == Constant),
3986 "constant pointers must have a value supplied" );
3987 // Ptr is never Null
3988 assert( ptr != Null, "null pointers are not typed" );
3989
3990 assert(instance_id <= 0 || xk, "instances are always exactly typed");
3991 if (ptr == Constant) {
3992 // Note: This case includes meta-object constants, such as methods.
3993 xk = true;
3994 } else if (k->is_loaded()) {
3995 ciInstanceKlass* ik = k->as_instance_klass();
3996 if (!xk && ik->is_final()) xk = true; // no inexact final klass
3997 assert(!ik->is_interface(), "no interface here");
3998 if (xk && ik->is_interface()) xk = false; // no exact interface
3999 }
4000
4001 // Now hash this baby
4002 TypeInstPtr *result =
4003 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4004
4005 return result;
4006 }
4007
4008 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4009 if (k->is_instance_klass()) {
4010 if (k->is_loaded()) {
4011 if (k->is_interface() && interface_handling == ignore_interfaces) {
4012 assert(interface, "no interface expected");
4013 k = ciEnv::current()->Object_klass();
4014 const TypeInterfaces* interfaces = TypeInterfaces::make();
4015 return interfaces;
4016 }
4017 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4018 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4019 if (k->is_interface()) {
4020 assert(interface, "no interface expected");
4021 k = ciEnv::current()->Object_klass();
4022 } else {
4023 assert(klass, "no instance klass expected");
4049 switch (bt) {
4050 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4051 case T_INT: return TypeInt::make(constant.as_int());
4052 case T_CHAR: return TypeInt::make(constant.as_char());
4053 case T_BYTE: return TypeInt::make(constant.as_byte());
4054 case T_SHORT: return TypeInt::make(constant.as_short());
4055 case T_FLOAT: return TypeF::make(constant.as_float());
4056 case T_DOUBLE: return TypeD::make(constant.as_double());
4057 case T_LONG: return TypeLong::make(constant.as_long());
4058 default: break;
4059 }
4060 fatal("Invalid boxed value type '%s'", type2name(bt));
4061 return nullptr;
4062 }
4063
4064 //------------------------------cast_to_ptr_type-------------------------------
4065 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4066 if( ptr == _ptr ) return this;
4067 // Reconstruct _sig info here since not a problem with later lazy
4068 // construction, _sig will show up on demand.
4069 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4070 }
4071
4072
4073 //-----------------------------cast_to_exactness-------------------------------
4074 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4075 if( klass_is_exact == _klass_is_exact ) return this;
4076 if (!_klass->is_loaded()) return this;
4077 ciInstanceKlass* ik = _klass->as_instance_klass();
4078 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4079 assert(!ik->is_interface(), "no interface here");
4080 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4081 }
4082
4083 //-----------------------------cast_to_instance_id----------------------------
4084 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4085 if( instance_id == _instance_id ) return this;
4086 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4087 }
4088
4089 //------------------------------xmeet_unloaded---------------------------------
4090 // Compute the MEET of two InstPtrs when at least one is unloaded.
4091 // Assume classes are different since called after check for same name/class-loader
4092 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4093 int off = meet_offset(tinst->offset());
4094 PTR ptr = meet_ptr(tinst->ptr());
4095 int instance_id = meet_instance_id(tinst->instance_id());
4096 const TypePtr* speculative = xmeet_speculative(tinst);
4097 int depth = meet_inline_depth(tinst->inline_depth());
4098
4099 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4100 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4101 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4102 //
4103 // Meet unloaded class with java/lang/Object
4104 //
4105 // Meet
4106 // | Unloaded Class
4107 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4108 // ===================================================================
4109 // TOP | ..........................Unloaded......................|
4110 // AnyNull | U-AN |................Unloaded......................|
4111 // Constant | ... O-NN .................................. | O-BOT |
4112 // NotNull | ... O-NN .................................. | O-BOT |
4113 // BOTTOM | ........................Object-BOTTOM ..................|
4114 //
4115 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4116 //
4117 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4118 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4119 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4120 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4121 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4122 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4123 }
4124 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4125
4126 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4127 }
4128
4129 // Both are unloaded, not the same class, not Object
4130 // Or meet unloaded with a different loaded class, not java/lang/Object
4131 if (ptr != TypePtr::BotPTR) {
4132 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4133 }
4134 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4135 }
4136
4137
4138 //------------------------------meet-------------------------------------------
4162 case Top:
4163 return this;
4164
4165 default: // All else is a mistake
4166 typerr(t);
4167
4168 case MetadataPtr:
4169 case KlassPtr:
4170 case InstKlassPtr:
4171 case AryKlassPtr:
4172 case RawPtr: return TypePtr::BOTTOM;
4173
4174 case AryPtr: { // All arrays inherit from Object class
4175 // Call in reverse direction to avoid duplication
4176 return t->is_aryptr()->xmeet_helper(this);
4177 }
4178
4179 case OopPtr: { // Meeting to OopPtrs
4180 // Found a OopPtr type vs self-InstPtr type
4181 const TypeOopPtr *tp = t->is_oopptr();
4182 int offset = meet_offset(tp->offset());
4183 PTR ptr = meet_ptr(tp->ptr());
4184 switch (tp->ptr()) {
4185 case TopPTR:
4186 case AnyNull: {
4187 int instance_id = meet_instance_id(InstanceTop);
4188 const TypePtr* speculative = xmeet_speculative(tp);
4189 int depth = meet_inline_depth(tp->inline_depth());
4190 return make(ptr, klass(), _interfaces, klass_is_exact(),
4191 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4192 }
4193 case NotNull:
4194 case BotPTR: {
4195 int instance_id = meet_instance_id(tp->instance_id());
4196 const TypePtr* speculative = xmeet_speculative(tp);
4197 int depth = meet_inline_depth(tp->inline_depth());
4198 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4199 }
4200 default: typerr(t);
4201 }
4202 }
4203
4204 case AnyPtr: { // Meeting to AnyPtrs
4205 // Found an AnyPtr type vs self-InstPtr type
4206 const TypePtr *tp = t->is_ptr();
4207 int offset = meet_offset(tp->offset());
4208 PTR ptr = meet_ptr(tp->ptr());
4209 int instance_id = meet_instance_id(InstanceTop);
4210 const TypePtr* speculative = xmeet_speculative(tp);
4211 int depth = meet_inline_depth(tp->inline_depth());
4212 switch (tp->ptr()) {
4213 case Null:
4214 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4215 // else fall through to AnyNull
4216 case TopPTR:
4217 case AnyNull: {
4218 return make(ptr, klass(), _interfaces, klass_is_exact(),
4219 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4220 }
4221 case NotNull:
4222 case BotPTR:
4223 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4224 default: typerr(t);
4225 }
4226 }
4227
4228 /*
4229 A-top }
4230 / | \ } Tops
4231 B-top A-any C-top }
4232 | / | \ | } Any-nulls
4233 B-any | C-any }
4234 | | |
4235 B-con A-con C-con } constants; not comparable across classes
4236 | | |
4237 B-not | C-not }
4238 | \ | / | } not-nulls
4239 B-bot A-not C-bot }
4240 \ | / } Bottoms
4241 A-bot }
4242 */
4243
4244 case InstPtr: { // Meeting 2 Oops?
4245 // Found an InstPtr sub-type vs self-InstPtr type
4246 const TypeInstPtr *tinst = t->is_instptr();
4247 int off = meet_offset(tinst->offset());
4248 PTR ptr = meet_ptr(tinst->ptr());
4249 int instance_id = meet_instance_id(tinst->instance_id());
4250 const TypePtr* speculative = xmeet_speculative(tinst);
4251 int depth = meet_inline_depth(tinst->inline_depth());
4252 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4253
4254 ciKlass* tinst_klass = tinst->klass();
4255 ciKlass* this_klass = klass();
4256
4257 ciKlass* res_klass = nullptr;
4258 bool res_xk = false;
4259 const Type* res;
4260 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4261
4262 if (kind == UNLOADED) {
4263 // One of these classes has not been loaded
4264 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4265 #ifndef PRODUCT
4266 if (PrintOpto && Verbose) {
4267 tty->print("meet of unloaded classes resulted in: ");
4268 unloaded_meet->dump();
4269 tty->cr();
4270 tty->print(" this == ");
4271 dump();
4272 tty->cr();
4273 tty->print(" tinst == ");
4274 tinst->dump();
4275 tty->cr();
4276 }
4277 #endif
4278 res = unloaded_meet;
4279 } else {
4280 if (kind == NOT_SUBTYPE && instance_id > 0) {
4281 instance_id = InstanceBot;
4282 } else if (kind == LCA) {
4283 instance_id = InstanceBot;
4284 }
4285 ciObject* o = nullptr; // Assume not constant when done
4286 ciObject* this_oop = const_oop();
4287 ciObject* tinst_oop = tinst->const_oop();
4288 if (ptr == Constant) {
4289 if (this_oop != nullptr && tinst_oop != nullptr &&
4290 this_oop->equals(tinst_oop))
4291 o = this_oop;
4292 else if (above_centerline(_ptr)) {
4293 assert(!tinst_klass->is_interface(), "");
4294 o = tinst_oop;
4295 } else if (above_centerline(tinst->_ptr)) {
4296 assert(!this_klass->is_interface(), "");
4297 o = this_oop;
4298 } else
4299 ptr = NotNull;
4300 }
4301 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4302 }
4303
4304 return res;
4305
4306 } // End of case InstPtr
4307
4308 } // End of switch
4309 return this; // Return the double constant
4310 }
4311
4312 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4313 ciKlass*& res_klass, bool& res_xk) {
4314 ciKlass* this_klass = this_type->klass();
4315 ciKlass* other_klass = other_type->klass();
4316 bool this_xk = this_type->klass_is_exact();
4317 bool other_xk = other_type->klass_is_exact();
4318 PTR this_ptr = this_type->ptr();
4319 PTR other_ptr = other_type->ptr();
4320 const TypeInterfaces* this_interfaces = this_type->interfaces();
4321 const TypeInterfaces* other_interfaces = other_type->interfaces();
4322 // Check for easy case; klasses are equal (and perhaps not loaded!)
4323 // If we have constants, then we created oops so classes are loaded
4324 // and we can handle the constants further down. This case handles
4325 // both-not-loaded or both-loaded classes
4326 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4327 res_klass = this_klass;
4328 res_xk = this_xk;
4329 return QUICK;
4330 }
4331
4332 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4333 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4334 return UNLOADED;
4335 }
4341 // If both are up and they do NOT subtype, "fall hard".
4342 // If both are down and they subtype, take the supertype class.
4343 // If both are down and they do NOT subtype, "fall hard".
4344 // Constants treated as down.
4345
4346 // Now, reorder the above list; observe that both-down+subtype is also
4347 // "fall hard"; "fall hard" becomes the default case:
4348 // If we split one up & one down AND they subtype, take the down man.
4349 // If both are up and they subtype, take the subtype class.
4350
4351 // If both are down and they subtype, "fall hard".
4352 // If both are down and they do NOT subtype, "fall hard".
4353 // If both are up and they do NOT subtype, "fall hard".
4354 // If we split one up & one down AND they do NOT subtype, "fall hard".
4355
4356 // If a proper subtype is exact, and we return it, we return it exactly.
4357 // If a proper supertype is exact, there can be no subtyping relationship!
4358 // If both types are equal to the subtype, exactness is and-ed below the
4359 // centerline and or-ed above it. (N.B. Constants are always exact.)
4360
4361 // Check for subtyping:
4362 const T* subtype = nullptr;
4363 bool subtype_exact = false;
4364 if (this_type->is_same_java_type_as(other_type)) {
4365 subtype = this_type;
4366 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4367 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4368 subtype = this_type; // Pick subtyping class
4369 subtype_exact = this_xk;
4370 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4371 subtype = other_type; // Pick subtyping class
4372 subtype_exact = other_xk;
4373 }
4374
4375 if (subtype) {
4376 if (above_centerline(ptr)) { // both are up?
4377 this_type = other_type = subtype;
4378 this_xk = other_xk = subtype_exact;
4379 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4380 this_type = other_type; // tinst is down; keep down man
4381 this_xk = other_xk;
4382 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4383 other_type = this_type; // this is down; keep down man
4384 other_xk = this_xk;
4385 } else {
4386 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4387 }
4388 }
4389
4390 // Check for classes now being equal
4391 if (this_type->is_same_java_type_as(other_type)) {
4392 // If the klasses are equal, the constants may still differ. Fall to
4393 // NotNull if they do (neither constant is null; that is a special case
4394 // handled elsewhere).
4395 res_klass = this_type->klass();
4396 res_xk = this_xk;
4397 return SUBTYPE;
4398 } // Else classes are not equal
4399
4400 // Since klasses are different, we require a LCA in the Java
4401 // class hierarchy - which means we have to fall to at least NotNull.
4402 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4403 ptr = NotNull;
4404 }
4405
4406 interfaces = this_interfaces->intersection_with(other_interfaces);
4407
4408 // Now we find the LCA of Java classes
4409 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4410
4411 res_klass = k;
4412 res_xk = false;
4413
4414 return LCA;
4415 }
4416
4417 //------------------------java_mirror_type--------------------------------------
4418 ciType* TypeInstPtr::java_mirror_type() const {
4419 // must be a singleton type
4420 if( const_oop() == nullptr ) return nullptr;
4421
4422 // must be of type java.lang.Class
4423 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4424
4425 return const_oop()->as_instance()->java_mirror_type();
4426 }
4427
4428
4429 //------------------------------xdual------------------------------------------
4430 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4431 // inheritance mechanism.
4432 const Type *TypeInstPtr::xdual() const {
4433 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4434 }
4435
4436 //------------------------------eq---------------------------------------------
4437 // Structural equality check for Type representations
4438 bool TypeInstPtr::eq( const Type *t ) const {
4439 const TypeInstPtr *p = t->is_instptr();
4440 return
4441 klass()->equals(p->klass()) &&
4442 _interfaces->eq(p->_interfaces) &&
4443 TypeOopPtr::eq(p); // Check sub-type stuff
4444 }
4445
4446 //------------------------------hash-------------------------------------------
4447 // Type-specific hashing function.
4448 uint TypeInstPtr::hash(void) const {
4449 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4450 }
4451
4452 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4453 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4454 }
4455
4456
4457 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4458 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4459 }
4460
4461 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4462 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4463 }
4464
4465
4466 //------------------------------dump2------------------------------------------
4467 // Dump oop Type
4468 #ifndef PRODUCT
4469 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4473 _interfaces->dump(st);
4474
4475 if (_ptr == Constant && (WizardMode || Verbose)) {
4476 ResourceMark rm;
4477 stringStream ss;
4478
4479 st->print(" ");
4480 const_oop()->print_oop(&ss);
4481 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4482 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4483 char* buf = ss.as_string(/* c_heap= */false);
4484 StringUtils::replace_no_expand(buf, "\n", "");
4485 st->print_raw(buf);
4486 }
4487
4488 st->print(":%s", ptr_msg[_ptr]);
4489 if (_klass_is_exact) {
4490 st->print(":exact");
4491 }
4492
4493 dump_offset(st);
4494 dump_instance_id(st);
4495 dump_inline_depth(st);
4496 dump_speculative(st);
4497 }
4498 #endif
4499
4500 //------------------------------add_offset-------------------------------------
4501 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4502 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4503 _instance_id, add_offset_speculative(offset), _inline_depth);
4504 }
4505
4506 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4507 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4508 _instance_id, with_offset_speculative(offset), _inline_depth);
4509 }
4510
4511 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4512 if (_speculative == nullptr) {
4513 return this;
4514 }
4515 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4516 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4517 _instance_id, nullptr, _inline_depth);
4518 }
4519
4520 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4521 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4522 }
4523
4524 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4525 if (!UseInlineDepthForSpeculativeTypes) {
4526 return this;
4527 }
4528 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4529 }
4530
4531 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4532 assert(is_known_instance(), "should be known");
4533 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4534 }
4535
4536 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4537 bool xk = klass_is_exact();
4538 ciInstanceKlass* ik = klass()->as_instance_klass();
4539 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4540 if (_interfaces->eq(ik)) {
4541 Compile* C = Compile::current();
4542 Dependencies* deps = C->dependencies();
4543 deps->assert_leaf_type(ik);
4544 xk = true;
4545 }
4546 }
4547 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4548 }
4549
4550 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) {
4551 static_assert(std::is_base_of<T2, T1>::value, "");
4552
4553 if (!this_one->is_instance_type(other)) {
4554 return false;
4555 }
4556
4557 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4558 return true;
4559 }
4560
4561 return this_one->klass()->is_subtype_of(other->klass()) &&
4562 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4563 }
4564
4565
4566 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4567 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4572 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4573 return true;
4574 }
4575
4576 if (this_one->is_instance_type(other)) {
4577 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4578 }
4579
4580 int dummy;
4581 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4582 if (this_top_or_bottom) {
4583 return false;
4584 }
4585
4586 const T1* other_ary = this_one->is_array_type(other);
4587 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4588 const TypePtr* this_elem = this_one->elem()->make_ptr();
4589 if (other_elem != nullptr && this_elem != nullptr) {
4590 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4591 }
4592
4593 if (other_elem == nullptr && this_elem == nullptr) {
4594 return this_one->klass()->is_subtype_of(other->klass());
4595 }
4596
4597 return false;
4598 }
4599
4600 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4601 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4602 }
4603
4604 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4605 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4606 }
4607
4608 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *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 //=============================================================================
4613 // Convenience common pre-built types.
4614 const TypeAryPtr* TypeAryPtr::BOTTOM;
4615 const TypeAryPtr* TypeAryPtr::RANGE;
4616 const TypeAryPtr* TypeAryPtr::OOPS;
4617 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4618 const TypeAryPtr* TypeAryPtr::BYTES;
4619 const TypeAryPtr* TypeAryPtr::SHORTS;
4620 const TypeAryPtr* TypeAryPtr::CHARS;
4621 const TypeAryPtr* TypeAryPtr::INTS;
4622 const TypeAryPtr* TypeAryPtr::LONGS;
4623 const TypeAryPtr* TypeAryPtr::FLOATS;
4624 const TypeAryPtr* TypeAryPtr::DOUBLES;
4625
4626 //------------------------------make-------------------------------------------
4627 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4628 int instance_id, const TypePtr* speculative, int inline_depth) {
4629 assert(!(k == nullptr && ary->_elem->isa_int()),
4630 "integral arrays must be pre-equipped with a class");
4631 if (!xk) xk = ary->ary_must_be_exact();
4632 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4633 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4634 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4635 k = nullptr;
4636 }
4637 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4638 }
4639
4640 //------------------------------make-------------------------------------------
4641 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4642 int instance_id, const TypePtr* speculative, int inline_depth,
4643 bool is_autobox_cache) {
4644 assert(!(k == nullptr && ary->_elem->isa_int()),
4645 "integral arrays must be pre-equipped with a class");
4646 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4647 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4648 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4649 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4650 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4651 k = nullptr;
4652 }
4653 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4654 }
4655
4656 //------------------------------cast_to_ptr_type-------------------------------
4657 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4658 if( ptr == _ptr ) return this;
4659 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4660 }
4661
4662
4663 //-----------------------------cast_to_exactness-------------------------------
4664 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4665 if( klass_is_exact == _klass_is_exact ) return this;
4666 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4667 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4668 }
4669
4670 //-----------------------------cast_to_instance_id----------------------------
4671 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4672 if( instance_id == _instance_id ) return this;
4673 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4674 }
4675
4676
4677 //-----------------------------max_array_length-------------------------------
4678 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4679 jint TypeAryPtr::max_array_length(BasicType etype) {
4680 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4681 if (etype == T_NARROWOOP) {
4682 etype = T_OBJECT;
4683 } else if (etype == T_ILLEGAL) { // bottom[]
4684 etype = T_BYTE; // will produce conservatively high value
4685 } else {
4686 fatal("not an element type: %s", type2name(etype));
4687 }
4688 }
4689 return arrayOopDesc::max_array_length(etype);
4690 }
4691
4692 //-----------------------------narrow_size_type-------------------------------
4693 // Narrow the given size type to the index range for the given array base type.
4711 if (size->is_con()) {
4712 lo = hi;
4713 }
4714 chg = true;
4715 }
4716 // Negative length arrays will produce weird intermediate dead fast-path code
4717 if (lo > hi) {
4718 return TypeInt::ZERO;
4719 }
4720 if (!chg) {
4721 return size;
4722 }
4723 return TypeInt::make(lo, hi, Type::WidenMin);
4724 }
4725
4726 //-------------------------------cast_to_size----------------------------------
4727 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4728 assert(new_size != nullptr, "");
4729 new_size = narrow_size_type(new_size);
4730 if (new_size == size()) return this;
4731 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4732 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4733 }
4734
4735 //------------------------------cast_to_stable---------------------------------
4736 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4737 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4738 return this;
4739
4740 const Type* elem = this->elem();
4741 const TypePtr* elem_ptr = elem->make_ptr();
4742
4743 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4744 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4745 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4746 }
4747
4748 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4749
4750 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4751 }
4752
4753 //-----------------------------stable_dimension--------------------------------
4754 int TypeAryPtr::stable_dimension() const {
4755 if (!is_stable()) return 0;
4756 int dim = 1;
4757 const TypePtr* elem_ptr = elem()->make_ptr();
4758 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4759 dim += elem_ptr->is_aryptr()->stable_dimension();
4760 return dim;
4761 }
4762
4763 //----------------------cast_to_autobox_cache-----------------------------------
4764 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4765 if (is_autobox_cache()) return this;
4766 const TypeOopPtr* etype = elem()->make_oopptr();
4767 if (etype == nullptr) return this;
4768 // The pointers in the autobox arrays are always non-null.
4769 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4770 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4771 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4772 }
4773
4774 //------------------------------eq---------------------------------------------
4775 // Structural equality check for Type representations
4776 bool TypeAryPtr::eq( const Type *t ) const {
4777 const TypeAryPtr *p = t->is_aryptr();
4778 return
4779 _ary == p->_ary && // Check array
4780 TypeOopPtr::eq(p); // Check sub-parts
4781 }
4782
4783 //------------------------------hash-------------------------------------------
4784 // Type-specific hashing function.
4785 uint TypeAryPtr::hash(void) const {
4786 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4787 }
4788
4789 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4790 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4791 }
4792
4793 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4794 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4795 }
4796
4797 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4798 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4799 }
4800 //------------------------------meet-------------------------------------------
4801 // Compute the MEET of two types. It returns a new Type object.
4802 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4803 // Perform a fast test for common case; meeting the same types together.
4804 if( this == t ) return this; // Meeting same type-rep?
4805 // Current "this->_base" is Pointer
4806 switch (t->base()) { // switch on original type
4813 case HalfFloatBot:
4814 case FloatTop:
4815 case FloatCon:
4816 case FloatBot:
4817 case DoubleTop:
4818 case DoubleCon:
4819 case DoubleBot:
4820 case NarrowOop:
4821 case NarrowKlass:
4822 case Bottom: // Ye Olde Default
4823 return Type::BOTTOM;
4824 case Top:
4825 return this;
4826
4827 default: // All else is a mistake
4828 typerr(t);
4829
4830 case OopPtr: { // Meeting to OopPtrs
4831 // Found a OopPtr type vs self-AryPtr type
4832 const TypeOopPtr *tp = t->is_oopptr();
4833 int offset = meet_offset(tp->offset());
4834 PTR ptr = meet_ptr(tp->ptr());
4835 int depth = meet_inline_depth(tp->inline_depth());
4836 const TypePtr* speculative = xmeet_speculative(tp);
4837 switch (tp->ptr()) {
4838 case TopPTR:
4839 case AnyNull: {
4840 int instance_id = meet_instance_id(InstanceTop);
4841 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4842 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4843 }
4844 case BotPTR:
4845 case NotNull: {
4846 int instance_id = meet_instance_id(tp->instance_id());
4847 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4848 }
4849 default: ShouldNotReachHere();
4850 }
4851 }
4852
4853 case AnyPtr: { // Meeting two AnyPtrs
4854 // Found an AnyPtr type vs self-AryPtr type
4855 const TypePtr *tp = t->is_ptr();
4856 int offset = meet_offset(tp->offset());
4857 PTR ptr = meet_ptr(tp->ptr());
4858 const TypePtr* speculative = xmeet_speculative(tp);
4859 int depth = meet_inline_depth(tp->inline_depth());
4860 switch (tp->ptr()) {
4861 case TopPTR:
4862 return this;
4863 case BotPTR:
4864 case NotNull:
4865 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4866 case Null:
4867 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4868 // else fall through to AnyNull
4869 case AnyNull: {
4870 int instance_id = meet_instance_id(InstanceTop);
4871 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4872 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4873 }
4874 default: ShouldNotReachHere();
4875 }
4876 }
4877
4878 case MetadataPtr:
4879 case KlassPtr:
4880 case InstKlassPtr:
4881 case AryKlassPtr:
4882 case RawPtr: return TypePtr::BOTTOM;
4883
4884 case AryPtr: { // Meeting 2 references?
4885 const TypeAryPtr *tap = t->is_aryptr();
4886 int off = meet_offset(tap->offset());
4887 const Type* tm = _ary->meet_speculative(tap->_ary);
4888 const TypeAry* tary = tm->isa_ary();
4889 if (tary == nullptr) {
4890 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
4891 return tm;
4892 }
4893 PTR ptr = meet_ptr(tap->ptr());
4894 int instance_id = meet_instance_id(tap->instance_id());
4895 const TypePtr* speculative = xmeet_speculative(tap);
4896 int depth = meet_inline_depth(tap->inline_depth());
4897
4898 ciKlass* res_klass = nullptr;
4899 bool res_xk = false;
4900 const Type* elem = tary->_elem;
4901 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4902 instance_id = InstanceBot;
4903 }
4904
4905 ciObject* o = nullptr; // Assume not constant when done
4906 ciObject* this_oop = const_oop();
4907 ciObject* tap_oop = tap->const_oop();
4908 if (ptr == Constant) {
4909 if (this_oop != nullptr && tap_oop != nullptr &&
4910 this_oop->equals(tap_oop)) {
4911 o = tap_oop;
4912 } else if (above_centerline(_ptr)) {
4913 o = tap_oop;
4914 } else if (above_centerline(tap->_ptr)) {
4915 o = this_oop;
4916 } else {
4917 ptr = NotNull;
4918 }
4919 }
4920 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4921 }
4922
4923 // All arrays inherit from Object class
4924 case InstPtr: {
4925 const TypeInstPtr *tp = t->is_instptr();
4926 int offset = meet_offset(tp->offset());
4927 PTR ptr = meet_ptr(tp->ptr());
4928 int instance_id = meet_instance_id(tp->instance_id());
4929 const TypePtr* speculative = xmeet_speculative(tp);
4930 int depth = meet_inline_depth(tp->inline_depth());
4931 const TypeInterfaces* interfaces = meet_interfaces(tp);
4932 const TypeInterfaces* tp_interfaces = tp->_interfaces;
4933 const TypeInterfaces* this_interfaces = _interfaces;
4934
4935 switch (ptr) {
4936 case TopPTR:
4937 case AnyNull: // Fall 'down' to dual of object klass
4938 // For instances when a subclass meets a superclass we fall
4939 // below the centerline when the superclass is exact. We need to
4940 // do the same here.
4941 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4942 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4943 } else {
4944 // cannot subclass, so the meet has to fall badly below the centerline
4945 ptr = NotNull;
4946 instance_id = InstanceBot;
4947 interfaces = this_interfaces->intersection_with(tp_interfaces);
4948 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
4949 }
4950 case Constant:
4951 case NotNull:
4952 case BotPTR: // Fall down to object klass
4953 // LCA is object_klass, but if we subclass from the top we can do better
4954 if (above_centerline(tp->ptr())) {
4955 // If 'tp' is above the centerline and it is Object class
4956 // then we can subclass in the Java class hierarchy.
4957 // For instances when a subclass meets a superclass we fall
4958 // below the centerline when the superclass is exact. We need
4959 // to do the same here.
4960 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4961 // that is, my array type is a subtype of 'tp' klass
4962 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4963 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4964 }
4965 }
4966 // The other case cannot happen, since t cannot be a subtype of an array.
4967 // The meet falls down to Object class below centerline.
4968 if (ptr == Constant) {
4969 ptr = NotNull;
4970 }
4971 if (instance_id > 0) {
4972 instance_id = InstanceBot;
4973 }
4974 interfaces = this_interfaces->intersection_with(tp_interfaces);
4975 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
4976 default: typerr(t);
4977 }
4978 }
4979 }
4980 return this; // Lint noise
4981 }
4982
4983
4984 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
4985 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
4986 int dummy;
4987 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
4988 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
4989 ciKlass* this_klass = this_ary->klass();
4990 ciKlass* other_klass = other_ary->klass();
4991 bool this_xk = this_ary->klass_is_exact();
4992 bool other_xk = other_ary->klass_is_exact();
4993 PTR this_ptr = this_ary->ptr();
4994 PTR other_ptr = other_ary->ptr();
4995 res_klass = nullptr;
4996 MeetResult result = SUBTYPE;
4997 if (elem->isa_int()) {
4998 // Integral array element types have irrelevant lattice relations.
4999 // It is the klass that determines array layout, not the element type.
5000 if (this_top_or_bottom)
5001 res_klass = other_klass;
5002 else if (other_top_or_bottom || other_klass == this_klass) {
5003 res_klass = this_klass;
5004 } else {
5005 // Something like byte[int+] meets char[int+].
5006 // This must fall to bottom, not (int[-128..65535])[int+].
5007 // instance_id = InstanceBot;
5008 elem = Type::BOTTOM;
5009 result = NOT_SUBTYPE;
5010 if (above_centerline(ptr) || ptr == Constant) {
5011 ptr = NotNull;
5012 res_xk = false;
5013 return NOT_SUBTYPE;
5014 }
5015 }
5016 } else {// Non integral arrays.
5017 // Must fall to bottom if exact klasses in upper lattice
5018 // are not equal or super klass is exact.
5019 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5020 // meet with top[] and bottom[] are processed further down:
5021 !this_top_or_bottom && !other_top_or_bottom &&
5022 // both are exact and not equal:
5024 // 'tap' is exact and super or unrelated:
5025 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5026 // 'this' is exact and super or unrelated:
5027 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5028 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5029 elem = Type::BOTTOM;
5030 }
5031 ptr = NotNull;
5032 res_xk = false;
5033 return NOT_SUBTYPE;
5034 }
5035 }
5036
5037 res_xk = false;
5038 switch (other_ptr) {
5039 case AnyNull:
5040 case TopPTR:
5041 // Compute new klass on demand, do not use tap->_klass
5042 if (below_centerline(this_ptr)) {
5043 res_xk = this_xk;
5044 } else {
5045 res_xk = (other_xk || this_xk);
5046 }
5047 return result;
5048 case Constant: {
5049 if (this_ptr == Constant) {
5050 res_xk = true;
5051 } else if(above_centerline(this_ptr)) {
5052 res_xk = true;
5053 } else {
5054 // Only precise for identical arrays
5055 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5056 }
5057 return result;
5058 }
5059 case NotNull:
5060 case BotPTR:
5061 // Compute new klass on demand, do not use tap->_klass
5062 if (above_centerline(this_ptr)) {
5063 res_xk = other_xk;
5064 } else {
5065 res_xk = (other_xk && this_xk) &&
5066 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5067 }
5068 return result;
5069 default: {
5070 ShouldNotReachHere();
5071 return result;
5072 }
5073 }
5074 return result;
5075 }
5076
5077
5078 //------------------------------xdual------------------------------------------
5079 // Dual: compute field-by-field dual
5080 const Type *TypeAryPtr::xdual() const {
5081 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());
5082 }
5083
5084 //------------------------------dump2------------------------------------------
5085 #ifndef PRODUCT
5086 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5087 st->print("aryptr:");
5088 _ary->dump2(d, depth, st);
5089 _interfaces->dump(st);
5090
5091 if (_ptr == Constant) {
5092 const_oop()->print(st);
5093 }
5094
5095 st->print(":%s", ptr_msg[_ptr]);
5096 if (_klass_is_exact) {
5097 st->print(":exact");
5098 }
5099
5100 if( _offset != 0 ) {
5101 BasicType basic_elem_type = elem()->basic_type();
5102 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5103 if( _offset == OffsetTop ) st->print("+undefined");
5104 else if( _offset == OffsetBot ) st->print("+any");
5105 else if( _offset < header_size ) st->print("+%d", _offset);
5106 else {
5107 if (basic_elem_type == T_ILLEGAL) {
5108 st->print("+any");
5109 } else {
5110 int elem_size = type2aelembytes(basic_elem_type);
5111 st->print("[%d]", (_offset - header_size)/elem_size);
5112 }
5113 }
5114 }
5115
5116 dump_instance_id(st);
5117 dump_inline_depth(st);
5118 dump_speculative(st);
5119 }
5120 #endif
5121
5122 bool TypeAryPtr::empty(void) const {
5123 if (_ary->empty()) return true;
5124 return TypeOopPtr::empty();
5125 }
5126
5127 //------------------------------add_offset-------------------------------------
5128 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5129 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5130 }
5131
5132 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5133 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5134 }
5135
5136 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5137 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5138 }
5139
5140 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5141 if (_speculative == nullptr) {
5142 return this;
5143 }
5144 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5145 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5146 }
5147
5148 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5149 if (!UseInlineDepthForSpeculativeTypes) {
5150 return this;
5151 }
5152 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5153 }
5154
5155 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5156 assert(is_known_instance(), "should be known");
5157 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5158 }
5159
5160 //=============================================================================
5161
5162 //------------------------------hash-------------------------------------------
5163 // Type-specific hashing function.
5164 uint TypeNarrowPtr::hash(void) const {
5165 return _ptrtype->hash() + 7;
5166 }
5167
5168 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5169 return _ptrtype->singleton();
5170 }
5171
5172 bool TypeNarrowPtr::empty(void) const {
5173 return _ptrtype->empty();
5174 }
5175
5176 intptr_t TypeNarrowPtr::get_con() const {
5177 return _ptrtype->get_con();
5178 }
5179
5180 bool TypeNarrowPtr::eq( const Type *t ) const {
5181 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5235 case HalfFloatTop:
5236 case HalfFloatCon:
5237 case HalfFloatBot:
5238 case FloatTop:
5239 case FloatCon:
5240 case FloatBot:
5241 case DoubleTop:
5242 case DoubleCon:
5243 case DoubleBot:
5244 case AnyPtr:
5245 case RawPtr:
5246 case OopPtr:
5247 case InstPtr:
5248 case AryPtr:
5249 case MetadataPtr:
5250 case KlassPtr:
5251 case InstKlassPtr:
5252 case AryKlassPtr:
5253 case NarrowOop:
5254 case NarrowKlass:
5255
5256 case Bottom: // Ye Olde Default
5257 return Type::BOTTOM;
5258 case Top:
5259 return this;
5260
5261 default: // All else is a mistake
5262 typerr(t);
5263
5264 } // End of switch
5265
5266 return this;
5267 }
5268
5269 #ifndef PRODUCT
5270 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5271 _ptrtype->dump2(d, depth, st);
5272 }
5273 #endif
5274
5275 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5319 return (one == two) && TypePtr::eq(t);
5320 } else {
5321 return one->equals(two) && TypePtr::eq(t);
5322 }
5323 }
5324
5325 //------------------------------hash-------------------------------------------
5326 // Type-specific hashing function.
5327 uint TypeMetadataPtr::hash(void) const {
5328 return
5329 (metadata() ? metadata()->hash() : 0) +
5330 TypePtr::hash();
5331 }
5332
5333 //------------------------------singleton--------------------------------------
5334 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5335 // constants
5336 bool TypeMetadataPtr::singleton(void) const {
5337 // detune optimizer to not generate constant metadata + constant offset as a constant!
5338 // TopPTR, Null, AnyNull, Constant are all singletons
5339 return (_offset == 0) && !below_centerline(_ptr);
5340 }
5341
5342 //------------------------------add_offset-------------------------------------
5343 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5344 return make( _ptr, _metadata, xadd_offset(offset));
5345 }
5346
5347 //-----------------------------filter------------------------------------------
5348 // Do not allow interface-vs.-noninterface joins to collapse to top.
5349 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5350 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5351 if (ft == nullptr || ft->empty())
5352 return Type::TOP; // Canonical empty value
5353 return ft;
5354 }
5355
5356 //------------------------------get_con----------------------------------------
5357 intptr_t TypeMetadataPtr::get_con() const {
5358 assert( _ptr == Null || _ptr == Constant, "" );
5359 assert( _offset >= 0, "" );
5360
5361 if (_offset != 0) {
5362 // After being ported to the compiler interface, the compiler no longer
5363 // directly manipulates the addresses of oops. Rather, it only has a pointer
5364 // to a handle at compile time. This handle is embedded in the generated
5365 // code and dereferenced at the time the nmethod is made. Until that time,
5366 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5367 // have access to the addresses!). This does not seem to currently happen,
5368 // but this assertion here is to help prevent its occurrence.
5369 tty->print_cr("Found oop constant with non-zero offset");
5370 ShouldNotReachHere();
5371 }
5372
5373 return (intptr_t)metadata()->constant_encoding();
5374 }
5375
5376 //------------------------------cast_to_ptr_type-------------------------------
5377 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5378 if( ptr == _ptr ) return this;
5379 return make(ptr, metadata(), _offset);
5380 }
5381
5395 case HalfFloatBot:
5396 case FloatTop:
5397 case FloatCon:
5398 case FloatBot:
5399 case DoubleTop:
5400 case DoubleCon:
5401 case DoubleBot:
5402 case NarrowOop:
5403 case NarrowKlass:
5404 case Bottom: // Ye Olde Default
5405 return Type::BOTTOM;
5406 case Top:
5407 return this;
5408
5409 default: // All else is a mistake
5410 typerr(t);
5411
5412 case AnyPtr: {
5413 // Found an AnyPtr type vs self-OopPtr type
5414 const TypePtr *tp = t->is_ptr();
5415 int offset = meet_offset(tp->offset());
5416 PTR ptr = meet_ptr(tp->ptr());
5417 switch (tp->ptr()) {
5418 case Null:
5419 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5420 // else fall through:
5421 case TopPTR:
5422 case AnyNull: {
5423 return make(ptr, _metadata, offset);
5424 }
5425 case BotPTR:
5426 case NotNull:
5427 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5428 default: typerr(t);
5429 }
5430 }
5431
5432 case RawPtr:
5433 case KlassPtr:
5434 case InstKlassPtr:
5435 case AryKlassPtr:
5436 case OopPtr:
5437 case InstPtr:
5438 case AryPtr:
5439 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5440
5441 case MetadataPtr: {
5442 const TypeMetadataPtr *tp = t->is_metadataptr();
5443 int offset = meet_offset(tp->offset());
5444 PTR tptr = tp->ptr();
5445 PTR ptr = meet_ptr(tptr);
5446 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5447 if (tptr == TopPTR || _ptr == TopPTR ||
5448 metadata()->equals(tp->metadata())) {
5449 return make(ptr, md, offset);
5450 }
5451 // metadata is different
5452 if( ptr == Constant ) { // Cannot be equal constants, so...
5453 if( tptr == Constant && _ptr != Constant) return t;
5454 if( _ptr == Constant && tptr != Constant) return this;
5455 ptr = NotNull; // Fall down in lattice
5456 }
5457 return make(ptr, nullptr, offset);
5458 break;
5459 }
5460 } // End of switch
5461 return this; // Return the double constant
5462 }
5463
5467 const Type *TypeMetadataPtr::xdual() const {
5468 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5469 }
5470
5471 //------------------------------dump2------------------------------------------
5472 #ifndef PRODUCT
5473 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5474 st->print("metadataptr:%s", ptr_msg[_ptr]);
5475 if (metadata() != nullptr) {
5476 st->print(":" INTPTR_FORMAT, p2i(metadata()));
5477 }
5478 dump_offset(st);
5479 }
5480 #endif
5481
5482
5483 //=============================================================================
5484 // Convenience common pre-built type.
5485 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5486
5487 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5488 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5489 }
5490
5491 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5492 return make(Constant, m, 0);
5493 }
5494 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5495 return make(Constant, m, 0);
5496 }
5497
5498 //------------------------------make-------------------------------------------
5499 // Create a meta data constant
5500 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5501 assert(m == nullptr || !m->is_klass(), "wrong type");
5502 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5503 }
5504
5505
5506 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5507 const Type* elem = _ary->_elem;
5508 bool xk = klass_is_exact();
5509 if (elem->make_oopptr() != nullptr) {
5510 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5511 if (elem->is_klassptr()->klass_is_exact()) {
5512 xk = true;
5513 }
5514 }
5515 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5516 }
5517
5518 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5519 if (klass->is_instance_klass()) {
5520 return TypeInstKlassPtr::make(klass, interface_handling);
5521 }
5522 return TypeAryKlassPtr::make(klass, interface_handling);
5523 }
5524
5525 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5526 if (klass->is_instance_klass()) {
5527 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5528 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5529 }
5530 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5531 }
5532
5533
5534 //------------------------------TypeKlassPtr-----------------------------------
5535 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5536 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5537 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5538 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5539 }
5540
5541 // Is there a single ciKlass* that can represent that type?
5542 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5543 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5544 if (_interfaces->empty()) {
5545 return _klass;
5546 }
5547 if (_klass != ciEnv::current()->Object_klass()) {
5548 if (_interfaces->eq(_klass->as_instance_klass())) {
5549 return _klass;
5550 }
5551 return nullptr;
5552 }
5553 return _interfaces->exact_klass();
5554 }
5555
5556 //------------------------------eq---------------------------------------------
5557 // Structural equality check for Type representations
5558 bool TypeKlassPtr::eq(const Type *t) const {
5559 const TypeKlassPtr *p = t->is_klassptr();
5560 return
5561 _interfaces->eq(p->_interfaces) &&
5562 TypePtr::eq(p);
5563 }
5564
5565 //------------------------------hash-------------------------------------------
5566 // Type-specific hashing function.
5567 uint TypeKlassPtr::hash(void) const {
5568 return TypePtr::hash() + _interfaces->hash();
5569 }
5570
5571 //------------------------------singleton--------------------------------------
5572 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5573 // constants
5574 bool TypeKlassPtr::singleton(void) const {
5575 // detune optimizer to not generate constant klass + constant offset as a constant!
5576 // TopPTR, Null, AnyNull, Constant are all singletons
5577 return (_offset == 0) && !below_centerline(_ptr);
5578 }
5579
5580 // Do not allow interface-vs.-noninterface joins to collapse to top.
5581 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5582 // logic here mirrors the one from TypeOopPtr::filter. See comments
5583 // there.
5584 const Type* ft = join_helper(kills, include_speculative);
5585
5586 if (ft->empty()) {
5587 return Type::TOP; // Canonical empty value
5588 }
5589
5590 return ft;
5591 }
5592
5593 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5594 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5595 return _interfaces->union_with(other->_interfaces);
5596 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5597 return other->_interfaces;
5598 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5599 return _interfaces;
5600 }
5601 return _interfaces->intersection_with(other->_interfaces);
5602 }
5603
5604 //------------------------------get_con----------------------------------------
5605 intptr_t TypeKlassPtr::get_con() const {
5606 assert( _ptr == Null || _ptr == Constant, "" );
5607 assert( _offset >= 0, "" );
5608
5609 if (_offset != 0) {
5610 // After being ported to the compiler interface, the compiler no longer
5611 // directly manipulates the addresses of oops. Rather, it only has a pointer
5612 // to a handle at compile time. This handle is embedded in the generated
5613 // code and dereferenced at the time the nmethod is made. Until that time,
5614 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5615 // have access to the addresses!). This does not seem to currently happen,
5616 // but this assertion here is to help prevent its occurrence.
5617 tty->print_cr("Found oop constant with non-zero offset");
5618 ShouldNotReachHere();
5619 }
5620
5621 ciKlass* k = exact_klass();
5622
5623 return (intptr_t)k->constant_encoding();
5624 }
5625
5626 //=============================================================================
5627 // Convenience common pre-built types.
5628
5629 // Not-null object klass or below
5630 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5631 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5632
5633 bool TypeInstKlassPtr::eq(const Type *t) const {
5634 const TypeKlassPtr *p = t->is_klassptr();
5635 return
5636 klass()->equals(p->klass()) &&
5637 TypeKlassPtr::eq(p);
5638 }
5639
5640 uint TypeInstKlassPtr::hash(void) const {
5641 return klass()->hash() + TypeKlassPtr::hash();
5642 }
5643
5644 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5645 TypeInstKlassPtr *r =
5646 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5647
5648 return r;
5649 }
5650
5651 //------------------------------add_offset-------------------------------------
5652 // Access internals of klass object
5653 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5654 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5655 }
5656
5657 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5658 return make(_ptr, klass(), _interfaces, offset);
5659 }
5660
5661 //------------------------------cast_to_ptr_type-------------------------------
5662 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5663 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5664 if( ptr == _ptr ) return this;
5665 return make(ptr, _klass, _interfaces, _offset);
5666 }
5667
5668
5669 bool TypeInstKlassPtr::must_be_exact() const {
5670 if (!_klass->is_loaded()) return false;
5671 ciInstanceKlass* ik = _klass->as_instance_klass();
5672 if (ik->is_final()) return true; // cannot clear xk
5673 return false;
5674 }
5675
5676 //-----------------------------cast_to_exactness-------------------------------
5677 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5678 if (klass_is_exact == (_ptr == Constant)) return this;
5679 if (must_be_exact()) return this;
5680 ciKlass* k = klass();
5681 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5682 }
5683
5684
5685 //-----------------------------as_instance_type--------------------------------
5686 // Corresponding type for an instance of the given class.
5687 // It will be NotNull, and exact if and only if the klass type is exact.
5688 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5689 ciKlass* k = klass();
5690 bool xk = klass_is_exact();
5691 Compile* C = Compile::current();
5692 Dependencies* deps = C->dependencies();
5693 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5694 // Element is an instance
5695 bool klass_is_exact = false;
5696 const TypeInterfaces* interfaces = _interfaces;
5697 if (k->is_loaded()) {
5698 // Try to set klass_is_exact.
5699 ciInstanceKlass* ik = k->as_instance_klass();
5700 klass_is_exact = ik->is_final();
5701 if (!klass_is_exact && klass_change
5702 && deps != nullptr && UseUniqueSubclasses) {
5703 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5704 if (sub != nullptr) {
5705 if (_interfaces->eq(sub)) {
5706 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5707 k = ik = sub;
5708 xk = sub->is_final();
5709 }
5710 }
5711 }
5712 }
5713 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5714 }
5715
5716 //------------------------------xmeet------------------------------------------
5717 // Compute the MEET of two types, return a new Type object.
5718 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
5719 // Perform a fast test for common case; meeting the same types together.
5720 if( this == t ) return this; // Meeting same type-rep?
5721
5722 // Current "this->_base" is Pointer
5723 switch (t->base()) { // switch on original type
5724
5725 case Int: // Mixing ints & oops happens when javac
5726 case Long: // reuses local variables
5727 case HalfFloatTop:
5728 case HalfFloatCon:
5729 case HalfFloatBot:
5730 case FloatTop:
5731 case FloatCon:
5732 case FloatBot:
5733 case DoubleTop:
5734 case DoubleCon:
5735 case DoubleBot:
5736 case NarrowOop:
5737 case NarrowKlass:
5738 case Bottom: // Ye Olde Default
5739 return Type::BOTTOM;
5740 case Top:
5741 return this;
5742
5743 default: // All else is a mistake
5744 typerr(t);
5745
5746 case AnyPtr: { // Meeting to AnyPtrs
5747 // Found an AnyPtr type vs self-KlassPtr type
5748 const TypePtr *tp = t->is_ptr();
5749 int offset = meet_offset(tp->offset());
5750 PTR ptr = meet_ptr(tp->ptr());
5751 switch (tp->ptr()) {
5752 case TopPTR:
5753 return this;
5754 case Null:
5755 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5756 case AnyNull:
5757 return make( ptr, klass(), _interfaces, offset );
5758 case BotPTR:
5759 case NotNull:
5760 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5761 default: typerr(t);
5762 }
5763 }
5764
5765 case RawPtr:
5766 case MetadataPtr:
5767 case OopPtr:
5768 case AryPtr: // Meet with AryPtr
5769 case InstPtr: // Meet with InstPtr
5770 return TypePtr::BOTTOM;
5771
5772 //
5773 // A-top }
5774 // / | \ } Tops
5775 // B-top A-any C-top }
5776 // | / | \ | } Any-nulls
5777 // B-any | C-any }
5778 // | | |
5779 // B-con A-con C-con } constants; not comparable across classes
5780 // | | |
5781 // B-not | C-not }
5782 // | \ | / | } not-nulls
5783 // B-bot A-not C-bot }
5784 // \ | / } Bottoms
5785 // A-bot }
5786 //
5787
5788 case InstKlassPtr: { // Meet two KlassPtr types
5789 const TypeInstKlassPtr *tkls = t->is_instklassptr();
5790 int off = meet_offset(tkls->offset());
5791 PTR ptr = meet_ptr(tkls->ptr());
5792 const TypeInterfaces* interfaces = meet_interfaces(tkls);
5793
5794 ciKlass* res_klass = nullptr;
5795 bool res_xk = false;
5796 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5797 case UNLOADED:
5798 ShouldNotReachHere();
5799 case SUBTYPE:
5800 case NOT_SUBTYPE:
5801 case LCA:
5802 case QUICK: {
5803 assert(res_xk == (ptr == Constant), "");
5804 const Type* res = make(ptr, res_klass, interfaces, off);
5805 return res;
5806 }
5807 default:
5808 ShouldNotReachHere();
5809 }
5810 } // End of case KlassPtr
5811 case AryKlassPtr: { // All arrays inherit from Object class
5812 const TypeAryKlassPtr *tp = t->is_aryklassptr();
5813 int offset = meet_offset(tp->offset());
5814 PTR ptr = meet_ptr(tp->ptr());
5815 const TypeInterfaces* interfaces = meet_interfaces(tp);
5816 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5817 const TypeInterfaces* this_interfaces = _interfaces;
5818
5819 switch (ptr) {
5820 case TopPTR:
5821 case AnyNull: // Fall 'down' to dual of object klass
5822 // For instances when a subclass meets a superclass we fall
5823 // below the centerline when the superclass is exact. We need to
5824 // do the same here.
5825 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5826 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5827 } else {
5828 // cannot subclass, so the meet has to fall badly below the centerline
5829 ptr = NotNull;
5830 interfaces = _interfaces->intersection_with(tp->_interfaces);
5831 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5832 }
5833 case Constant:
5834 case NotNull:
5835 case BotPTR: // Fall down to object klass
5836 // LCA is object_klass, but if we subclass from the top we can do better
5837 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5838 // If 'this' (InstPtr) is above the centerline and it is Object class
5839 // then we can subclass in the Java class hierarchy.
5840 // For instances when a subclass meets a superclass we fall
5841 // below the centerline when the superclass is exact. We need
5842 // to do the same here.
5843 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5844 // that is, tp's array type is a subtype of my klass
5845 return TypeAryKlassPtr::make(ptr,
5846 tp->elem(), tp->klass(), offset);
5847 }
5848 }
5849 // The other case cannot happen, since I cannot be a subtype of an array.
5850 // The meet falls down to Object class below centerline.
5851 if( ptr == Constant )
5852 ptr = NotNull;
5853 interfaces = this_interfaces->intersection_with(tp_interfaces);
5854 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5855 default: typerr(t);
5856 }
5857 }
5858
5859 } // End of switch
5860 return this; // Return the double constant
5861 }
5862
5863 //------------------------------xdual------------------------------------------
5864 // Dual: compute field-by-field dual
5865 const Type *TypeInstKlassPtr::xdual() const {
5866 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5867 }
5868
5869 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) {
5870 static_assert(std::is_base_of<T2, T1>::value, "");
5871 if (!this_one->is_loaded() || !other->is_loaded()) {
5872 return false;
5873 }
5874 if (!this_one->is_instance_type(other)) {
5875 return false;
5876 }
5877
5878 if (!other_exact) {
5879 return false;
5880 }
5881
5882 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5883 return true;
5884 }
5885
5886 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5940
5941 if (this_exact) {
5942 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5943 }
5944
5945 return true;
5946 }
5947
5948 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5949 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5950 }
5951
5952 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
5953 if (!UseUniqueSubclasses) {
5954 return this;
5955 }
5956 ciKlass* k = klass();
5957 Compile* C = Compile::current();
5958 Dependencies* deps = C->dependencies();
5959 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5960 const TypeInterfaces* interfaces = _interfaces;
5961 if (k->is_loaded()) {
5962 ciInstanceKlass* ik = k->as_instance_klass();
5963 bool klass_is_exact = ik->is_final();
5964 if (!klass_is_exact &&
5965 deps != nullptr) {
5966 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5967 if (sub != nullptr) {
5968 if (_interfaces->eq(sub)) {
5969 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5970 k = ik = sub;
5971 klass_is_exact = sub->is_final();
5972 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
5973 }
5974 }
5975 }
5976 }
5977 return this;
5978 }
5979
5980 #ifndef PRODUCT
5981 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
5982 st->print("instklassptr:");
5983 klass()->print_name_on(st);
5984 _interfaces->dump(st);
5985 st->print(":%s", ptr_msg[_ptr]);
5986 dump_offset(st);
5987 }
5988 #endif // PRODUCT
5989
5990 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5991 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5992 }
5993
5994 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
5995 if (k->is_obj_array_klass()) {
5996 // Element is an object array. Recursively call ourself.
5997 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
5998 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
5999 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6000 } else if (k->is_type_array_klass()) {
6001 // Element is an typeArray
6002 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6003 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6004 } else {
6005 ShouldNotReachHere();
6006 return nullptr;
6007 }
6008 }
6009
6010 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6011 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6012 }
6013
6014 //------------------------------eq---------------------------------------------
6015 // Structural equality check for Type representations
6016 bool TypeAryKlassPtr::eq(const Type *t) const {
6017 const TypeAryKlassPtr *p = t->is_aryklassptr();
6018 return
6019 _elem == p->_elem && // Check array
6020 TypeKlassPtr::eq(p); // Check sub-parts
6021 }
6022
6023 //------------------------------hash-------------------------------------------
6024 // Type-specific hashing function.
6025 uint TypeAryKlassPtr::hash(void) const {
6026 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6027 }
6028
6029 //----------------------compute_klass------------------------------------------
6030 // Compute the defining klass for this class
6031 ciKlass* TypeAryPtr::compute_klass() const {
6032 // Compute _klass based on element type.
6033 ciKlass* k_ary = nullptr;
6034 const TypeInstPtr *tinst;
6035 const TypeAryPtr *tary;
6036 const Type* el = elem();
6037 if (el->isa_narrowoop()) {
6038 el = el->make_ptr();
6039 }
6040
6041 // Get element klass
6042 if ((tinst = el->isa_instptr()) != nullptr) {
6043 // Leave k_ary at null.
6044 } else if ((tary = el->isa_aryptr()) != nullptr) {
6045 // Leave k_ary at null.
6046 } else if ((el->base() == Type::Top) ||
6047 (el->base() == Type::Bottom)) {
6048 // element type of Bottom occurs from meet of basic type
6049 // and object; Top occurs when doing join on Bottom.
6050 // Leave k_ary at null.
6051 } else {
6052 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6053 // Compute array klass directly from basic type
6054 k_ary = ciTypeArrayKlass::make(el->basic_type());
6055 }
6056 return k_ary;
6057 }
6058
6059 //------------------------------klass------------------------------------------
6060 // Return the defining klass for this class
6061 ciKlass* TypeAryPtr::klass() const {
6062 if( _klass ) return _klass; // Return cached value, if possible
6063
6064 // Oops, need to compute _klass and cache it
6065 ciKlass* k_ary = compute_klass();
6073 // type TypeAryPtr::OOPS. This Type is shared between all
6074 // active compilations. However, the ciKlass which represents
6075 // this Type is *not* shared between compilations, so caching
6076 // this value would result in fetching a dangling pointer.
6077 //
6078 // Recomputing the underlying ciKlass for each request is
6079 // a bit less efficient than caching, but calls to
6080 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6081 ((TypeAryPtr*)this)->_klass = k_ary;
6082 }
6083 return k_ary;
6084 }
6085
6086 // Is there a single ciKlass* that can represent that type?
6087 ciKlass* TypeAryPtr::exact_klass_helper() const {
6088 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6089 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6090 if (k == nullptr) {
6091 return nullptr;
6092 }
6093 k = ciObjArrayKlass::make(k);
6094 return k;
6095 }
6096
6097 return klass();
6098 }
6099
6100 const Type* TypeAryPtr::base_element_type(int& dims) const {
6101 const Type* elem = this->elem();
6102 dims = 1;
6103 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6104 elem = elem->make_ptr()->is_aryptr()->elem();
6105 dims++;
6106 }
6107 return elem;
6108 }
6109
6110 //------------------------------add_offset-------------------------------------
6111 // Access internals of klass object
6112 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6113 return make(_ptr, elem(), klass(), xadd_offset(offset));
6114 }
6115
6116 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6117 return make(_ptr, elem(), klass(), offset);
6118 }
6119
6120 //------------------------------cast_to_ptr_type-------------------------------
6121 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6122 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6123 if (ptr == _ptr) return this;
6124 return make(ptr, elem(), _klass, _offset);
6125 }
6126
6127 bool TypeAryKlassPtr::must_be_exact() const {
6128 if (_elem == Type::BOTTOM) return false;
6129 if (_elem == Type::TOP ) return false;
6130 const TypeKlassPtr* tk = _elem->isa_klassptr();
6131 if (!tk) return true; // a primitive type, like int
6132 return tk->must_be_exact();
6133 }
6134
6135
6136 //-----------------------------cast_to_exactness-------------------------------
6137 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6138 if (must_be_exact()) return this; // cannot clear xk
6139 ciKlass* k = _klass;
6140 const Type* elem = this->elem();
6141 if (elem->isa_klassptr() && !klass_is_exact) {
6142 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6143 }
6144 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6145 }
6146
6147
6148 //-----------------------------as_instance_type--------------------------------
6149 // Corresponding type for an instance of the given class.
6150 // It will be NotNull, and exact if and only if the klass type is exact.
6151 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6152 ciKlass* k = klass();
6153 bool xk = klass_is_exact();
6154 const Type* el = nullptr;
6155 if (elem()->isa_klassptr()) {
6156 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6157 k = nullptr;
6158 } else {
6159 el = elem();
6160 }
6161 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6162 }
6163
6164
6165 //------------------------------xmeet------------------------------------------
6166 // Compute the MEET of two types, return a new Type object.
6167 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6168 // Perform a fast test for common case; meeting the same types together.
6169 if( this == t ) return this; // Meeting same type-rep?
6170
6171 // Current "this->_base" is Pointer
6172 switch (t->base()) { // switch on original type
6173
6174 case Int: // Mixing ints & oops happens when javac
6175 case Long: // reuses local variables
6176 case HalfFloatTop:
6177 case HalfFloatCon:
6178 case HalfFloatBot:
6179 case FloatTop:
6180 case FloatCon:
6181 case FloatBot:
6182 case DoubleTop:
6183 case DoubleCon:
6184 case DoubleBot:
6185 case NarrowOop:
6186 case NarrowKlass:
6187 case Bottom: // Ye Olde Default
6188 return Type::BOTTOM;
6189 case Top:
6190 return this;
6191
6192 default: // All else is a mistake
6193 typerr(t);
6194
6195 case AnyPtr: { // Meeting to AnyPtrs
6196 // Found an AnyPtr type vs self-KlassPtr type
6197 const TypePtr *tp = t->is_ptr();
6198 int offset = meet_offset(tp->offset());
6199 PTR ptr = meet_ptr(tp->ptr());
6200 switch (tp->ptr()) {
6201 case TopPTR:
6202 return this;
6203 case Null:
6204 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6205 case AnyNull:
6206 return make( ptr, _elem, klass(), offset );
6207 case BotPTR:
6208 case NotNull:
6209 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6210 default: typerr(t);
6211 }
6212 }
6213
6214 case RawPtr:
6215 case MetadataPtr:
6216 case OopPtr:
6217 case AryPtr: // Meet with AryPtr
6218 case InstPtr: // Meet with InstPtr
6219 return TypePtr::BOTTOM;
6220
6221 //
6222 // A-top }
6223 // / | \ } Tops
6224 // B-top A-any C-top }
6225 // | / | \ | } Any-nulls
6226 // B-any | C-any }
6227 // | | |
6228 // B-con A-con C-con } constants; not comparable across classes
6229 // | | |
6230 // B-not | C-not }
6231 // | \ | / | } not-nulls
6232 // B-bot A-not C-bot }
6233 // \ | / } Bottoms
6234 // A-bot }
6235 //
6236
6237 case AryKlassPtr: { // Meet two KlassPtr types
6238 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6239 int off = meet_offset(tap->offset());
6240 const Type* elem = _elem->meet(tap->_elem);
6241
6242 PTR ptr = meet_ptr(tap->ptr());
6243 ciKlass* res_klass = nullptr;
6244 bool res_xk = false;
6245 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6246 assert(res_xk == (ptr == Constant), "");
6247 return make(ptr, elem, res_klass, off);
6248 } // End of case KlassPtr
6249 case InstKlassPtr: {
6250 const TypeInstKlassPtr *tp = t->is_instklassptr();
6251 int offset = meet_offset(tp->offset());
6252 PTR ptr = meet_ptr(tp->ptr());
6253 const TypeInterfaces* interfaces = meet_interfaces(tp);
6254 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6255 const TypeInterfaces* this_interfaces = _interfaces;
6256
6257 switch (ptr) {
6258 case TopPTR:
6259 case AnyNull: // Fall 'down' to dual of object klass
6260 // For instances when a subclass meets a superclass we fall
6261 // below the centerline when the superclass is exact. We need to
6262 // do the same here.
6263 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6264 !tp->klass_is_exact()) {
6265 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6266 } else {
6267 // cannot subclass, so the meet has to fall badly below the centerline
6268 ptr = NotNull;
6269 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6270 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6271 }
6272 case Constant:
6273 case NotNull:
6274 case BotPTR: // Fall down to object klass
6275 // LCA is object_klass, but if we subclass from the top we can do better
6276 if (above_centerline(tp->ptr())) {
6277 // If 'tp' is above the centerline and it is Object class
6278 // then we can subclass in the Java class hierarchy.
6279 // For instances when a subclass meets a superclass we fall
6280 // below the centerline when the superclass is exact. We need
6281 // to do the same here.
6282 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6283 !tp->klass_is_exact()) {
6284 // that is, my array type is a subtype of 'tp' klass
6285 return make(ptr, _elem, _klass, offset);
6286 }
6287 }
6288 // The other case cannot happen, since t cannot be a subtype of an array.
6289 // The meet falls down to Object class below centerline.
6290 if (ptr == Constant)
6291 ptr = NotNull;
6292 interfaces = this_interfaces->intersection_with(tp_interfaces);
6293 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6294 default: typerr(t);
6295 }
6296 }
6297
6298 } // End of switch
6299 return this; // Return the double constant
6300 }
6301
6302 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) {
6303 static_assert(std::is_base_of<T2, T1>::value, "");
6304
6305 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6306 return true;
6307 }
6308
6309 int dummy;
6310 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6311
6312 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6313 return false;
6314 }
6315
6316 if (this_one->is_instance_type(other)) {
6317 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6318 other_exact;
6319 }
6320
6321 assert(this_one->is_array_type(other), "");
6322 const T1* other_ary = this_one->is_array_type(other);
6323 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6324 if (other_top_or_bottom) {
6325 return false;
6326 }
6327
6328 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6329 const TypePtr* this_elem = this_one->elem()->make_ptr();
6330 if (this_elem != nullptr && other_elem != nullptr) {
6331 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6332 }
6333 if (this_elem == nullptr && other_elem == nullptr) {
6334 return this_one->klass()->is_subtype_of(other->klass());
6335 }
6336 return false;
6337 }
6338
6339 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6340 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6341 }
6342
6343 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6344 static_assert(std::is_base_of<T2, T1>::value, "");
6345
6346 int dummy;
6347 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6348
6349 if (!this_one->is_array_type(other) ||
6350 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6403 }
6404
6405 const TypePtr* this_elem = this_one->elem()->make_ptr();
6406 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6407 if (other_elem != nullptr && this_elem != nullptr) {
6408 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6409 }
6410 if (other_elem == nullptr && this_elem == nullptr) {
6411 return this_one->klass()->is_subtype_of(other->klass());
6412 }
6413 return false;
6414 }
6415
6416 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6417 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6418 }
6419
6420 //------------------------------xdual------------------------------------------
6421 // Dual: compute field-by-field dual
6422 const Type *TypeAryKlassPtr::xdual() const {
6423 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6424 }
6425
6426 // Is there a single ciKlass* that can represent that type?
6427 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6428 if (elem()->isa_klassptr()) {
6429 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6430 if (k == nullptr) {
6431 return nullptr;
6432 }
6433 k = ciObjArrayKlass::make(k);
6434 return k;
6435 }
6436
6437 return klass();
6438 }
6439
6440 ciKlass* TypeAryKlassPtr::klass() const {
6441 if (_klass != nullptr) {
6442 return _klass;
6443 }
6444 ciKlass* k = nullptr;
6445 if (elem()->isa_klassptr()) {
6446 // leave null
6447 } else if ((elem()->base() == Type::Top) ||
6448 (elem()->base() == Type::Bottom)) {
6449 } else {
6450 k = ciTypeArrayKlass::make(elem()->basic_type());
6451 ((TypeAryKlassPtr*)this)->_klass = k;
6452 }
6453 return k;
6454 }
6455
6456 //------------------------------dump2------------------------------------------
6457 // Dump Klass Type
6458 #ifndef PRODUCT
6459 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6460 st->print("aryklassptr:[");
6461 _elem->dump2(d, depth, st);
6462 _interfaces->dump(st);
6463 st->print(":%s", ptr_msg[_ptr]);
6464 dump_offset(st);
6465 }
6466 #endif
6467
6468 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6469 const Type* elem = this->elem();
6470 dims = 1;
6471 while (elem->isa_aryklassptr()) {
6472 elem = elem->is_aryklassptr()->elem();
6473 dims++;
6474 }
6475 return elem;
6476 }
6477
6478 //=============================================================================
6479 // Convenience common pre-built types.
6480
6481 //------------------------------make-------------------------------------------
6482 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6483 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6484 }
6485
6486 //------------------------------make-------------------------------------------
6487 const TypeFunc *TypeFunc::make(ciMethod* method) {
6488 Compile* C = Compile::current();
6489 const TypeFunc* tf = C->last_tf(method); // check cache
6490 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6491 const TypeTuple *domain;
6492 if (method->is_static()) {
6493 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6494 } else {
6495 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6496 }
6497 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6498 tf = TypeFunc::make(domain, range);
6499 C->set_last_tf(method, tf); // fill cache
6500 return tf;
6501 }
6502
6503 //------------------------------meet-------------------------------------------
6504 // Compute the MEET of two types. It returns a new Type object.
6505 const Type *TypeFunc::xmeet( const Type *t ) const {
6506 // Perform a fast test for common case; meeting the same types together.
6507 if( this == t ) return this; // Meeting same type-rep?
6508
6509 // Current "this->_base" is Func
6510 switch (t->base()) { // switch on original type
6511
6512 case Bottom: // Ye Olde Default
6513 return t;
6514
6515 default: // All else is a mistake
6516 typerr(t);
6517
6518 case Top:
6519 break;
6520 }
6521 return this; // Return the double constant
6522 }
6523
6524 //------------------------------xdual------------------------------------------
6525 // Dual: compute field-by-field dual
6526 const Type *TypeFunc::xdual() const {
6527 return this;
6528 }
6529
6530 //------------------------------eq---------------------------------------------
6531 // Structural equality check for Type representations
6532 bool TypeFunc::eq( const Type *t ) const {
6533 const TypeFunc *a = (const TypeFunc*)t;
6534 return _domain == a->_domain &&
6535 _range == a->_range;
6536 }
6537
6538 //------------------------------hash-------------------------------------------
6539 // Type-specific hashing function.
6540 uint TypeFunc::hash(void) const {
6541 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6542 }
6543
6544 //------------------------------dump2------------------------------------------
6545 // Dump Function Type
6546 #ifndef PRODUCT
6547 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6548 if( _range->cnt() <= Parms )
6549 st->print("void");
6550 else {
6551 uint i;
6552 for (i = Parms; i < _range->cnt()-1; i++) {
6553 _range->field_at(i)->dump2(d,depth,st);
6554 st->print("/");
6555 }
6556 _range->field_at(i)->dump2(d,depth,st);
6557 }
6558 st->print(" ");
6559 st->print("( ");
6560 if( !depth || d[this] ) { // Check for recursive dump
6561 st->print("...)");
6562 return;
6563 }
6564 d.Insert((void*)this,(void*)this); // Stop recursion
6565 if (Parms < _domain->cnt())
6566 _domain->field_at(Parms)->dump2(d,depth-1,st);
6567 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6568 st->print(", ");
6569 _domain->field_at(i)->dump2(d,depth-1,st);
6570 }
6571 st->print(" )");
6572 }
6573 #endif
6574
6575 //------------------------------singleton--------------------------------------
6576 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6577 // constants (Ldi nodes). Singletons are integer, float or double constants
6578 // or a single symbol.
6579 bool TypeFunc::singleton(void) const {
6580 return false; // Never a singleton
6581 }
6582
6583 bool TypeFunc::empty(void) const {
6584 return false; // Never empty
6585 }
6586
6587
6588 BasicType TypeFunc::return_type() const{
6589 if (range()->cnt() == TypeFunc::Parms) {
6590 return T_VOID;
6591 }
6592 return range()->field_at(TypeFunc::Parms)->basic_type();
6593 }
|
1 /*
2 * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciField.hpp"
26 #include "ci/ciFlatArray.hpp"
27 #include "ci/ciFlatArrayKlass.hpp"
28 #include "ci/ciInlineKlass.hpp"
29 #include "ci/ciMethodData.hpp"
30 #include "ci/ciObjArrayKlass.hpp"
31 #include "ci/ciTypeFlow.hpp"
32 #include "classfile/javaClasses.hpp"
33 #include "classfile/symbolTable.hpp"
34 #include "classfile/vmSymbols.hpp"
35 #include "compiler/compileLog.hpp"
36 #include "libadt/dict.hpp"
37 #include "memory/oopFactory.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "oops/instanceKlass.hpp"
40 #include "oops/instanceMirrorKlass.hpp"
41 #include "oops/objArrayKlass.hpp"
42 #include "oops/typeArrayKlass.hpp"
43 #include "opto/arraycopynode.hpp"
44 #include "opto/callnode.hpp"
45 #include "opto/matcher.hpp"
46 #include "opto/node.hpp"
47 #include "opto/opcodes.hpp"
48 #include "opto/rangeinference.hpp"
49 #include "opto/runtime.hpp"
50 #include "opto/type.hpp"
51 #include "runtime/globals.hpp"
52 #include "runtime/stubRoutines.hpp"
53 #include "utilities/checkedCast.hpp"
54 #include "utilities/debug.hpp"
55 #include "utilities/globalDefinitions.hpp"
56 #include "utilities/ostream.hpp"
57 #include "utilities/powerOfTwo.hpp"
58 #include "utilities/stringUtils.hpp"
59
60 // Portions of code courtesy of Clifford Click
61
62 // Optimization - Graph Style
63
64 // Dictionary of types shared among compilations.
65 Dict* Type::_shared_type_dict = nullptr;
66 const Type::Offset Type::Offset::top(Type::OffsetTop);
67 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
68
69 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
70 // Either is 'TOP' offset? Return the other offset!
71 if (_offset == OffsetTop) return other;
72 if (other._offset == OffsetTop) return *this;
73 // If either is different, return 'BOTTOM' offset
74 if (_offset != other._offset) return bottom;
75 return Offset(_offset);
76 }
77
78 const Type::Offset Type::Offset::dual() const {
79 if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
80 if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
81 return Offset(_offset); // Map everything else into self
82 }
83
84 const Type::Offset Type::Offset::add(intptr_t offset) const {
85 // Adding to 'TOP' offset? Return 'TOP'!
86 if (_offset == OffsetTop || offset == OffsetTop) return top;
87 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
88 if (_offset == OffsetBot || offset == OffsetBot) return bottom;
89 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
90 offset += (intptr_t)_offset;
91 if (offset != (int)offset || offset == OffsetTop) return bottom;
92
93 // assert( _offset >= 0 && _offset+offset >= 0, "" );
94 // It is possible to construct a negative offset during PhaseCCP
95
96 return Offset((int)offset); // Sum valid offsets
97 }
98
99 void Type::Offset::dump2(outputStream *st) const {
100 if (_offset == 0) {
101 return;
102 } else if (_offset == OffsetTop) {
103 st->print("+top");
104 }
105 else if (_offset == OffsetBot) {
106 st->print("+bot");
107 } else if (_offset) {
108 st->print("+%d", _offset);
109 }
110 }
111
112 // Array which maps compiler types to Basic Types
113 const Type::TypeInfo Type::_type_info[Type::lastype] = {
114 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
115 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
116 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
117 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
118 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
119 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
120 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
121 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
122 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
123 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
124 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
125
126 #if defined(PPC64)
127 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
128 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
129 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
130 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
269 case ciTypeFlow::StateVector::T_NULL:
270 assert(type == ciTypeFlow::StateVector::null_type(), "");
271 return TypePtr::NULL_PTR;
272
273 case ciTypeFlow::StateVector::T_LONG2:
274 // The ciTypeFlow pass pushes a long, then the half.
275 // We do the same.
276 assert(type == ciTypeFlow::StateVector::long2_type(), "");
277 return TypeInt::TOP;
278
279 case ciTypeFlow::StateVector::T_DOUBLE2:
280 // The ciTypeFlow pass pushes double, then the half.
281 // Our convention is the same.
282 assert(type == ciTypeFlow::StateVector::double2_type(), "");
283 return Type::TOP;
284
285 case T_ADDRESS:
286 assert(type->is_return_address(), "");
287 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
288
289 case T_OBJECT:
290 return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
291
292 default:
293 // make sure we did not mix up the cases:
294 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
295 assert(type != ciTypeFlow::StateVector::top_type(), "");
296 assert(type != ciTypeFlow::StateVector::null_type(), "");
297 assert(type != ciTypeFlow::StateVector::long2_type(), "");
298 assert(type != ciTypeFlow::StateVector::double2_type(), "");
299 assert(!type->is_return_address(), "");
300
301 return Type::get_const_type(type);
302 }
303 }
304
305
306 //-----------------------make_from_constant------------------------------------
307 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
308 int stable_dimension, bool is_narrow_oop,
309 bool is_autobox_cache) {
310 switch (constant.basic_type()) {
311 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
361 case T_NARROWOOP: loadbt = T_OBJECT; break;
362 case T_ARRAY: loadbt = T_OBJECT; break;
363 case T_ADDRESS: loadbt = T_OBJECT; break;
364 default: break;
365 }
366 if (conbt == loadbt) {
367 if (is_unsigned && conbt == T_BYTE) {
368 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
369 return ciConstant(T_INT, con.as_int() & 0xFF);
370 } else {
371 return con;
372 }
373 }
374 if (conbt == T_SHORT && loadbt == T_CHAR) {
375 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
376 return ciConstant(T_INT, con.as_int() & 0xFFFF);
377 }
378 return ciConstant(); // T_ILLEGAL
379 }
380
381 static const Type* make_constant_from_non_flat_array_element(ciArray* array, int off, int stable_dimension,
382 BasicType loadbt, bool is_unsigned_load) {
383 // Decode the results of GraphKit::array_element_address.
384 ciConstant element_value = array->element_value_by_offset(off);
385 if (element_value.basic_type() == T_ILLEGAL) {
386 return nullptr; // wrong offset
387 }
388 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
389
390 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
391 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
392
393 if (con.is_valid() && // not a mismatched access
394 !con.is_null_or_zero()) { // not a default value
395 bool is_narrow_oop = (loadbt == T_NARROWOOP);
396 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
397 }
398 return nullptr;
399 }
400
401 static const Type* make_constant_from_flat_array_element(ciFlatArray* array, int off, int field_offset, int stable_dimension,
402 BasicType loadbt, bool is_unsigned_load) {
403 // Decode the results of GraphKit::array_element_address.
404 ciConstant element_value = array->field_value_by_offset(off + field_offset);
405 if (element_value.basic_type() == T_ILLEGAL) {
406 return nullptr; // wrong offset
407 }
408 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
409
410 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
411 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
412
413 if (con.is_valid() && // not a mismatched access
414 !con.is_null_or_zero()) { // not a default value
415 bool is_narrow_oop = (loadbt == T_NARROWOOP);
416 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
417 }
418 return nullptr;
419 }
420
421 // Try to constant-fold a stable array element.
422 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int field_offset, int stable_dimension,
423 BasicType loadbt, bool is_unsigned_load) {
424 if (array->is_flat()) {
425 return make_constant_from_flat_array_element(array->as_flat_array(), off, field_offset, stable_dimension, loadbt, is_unsigned_load);
426 }
427 return make_constant_from_non_flat_array_element(array, off, stable_dimension, loadbt, is_unsigned_load);
428 }
429
430 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
431 ciField* field;
432 ciType* type = holder->java_mirror_type();
433 if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
434 // Static field
435 field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
436 } else {
437 // Instance field
438 field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
439 }
440 if (field == nullptr) {
441 return nullptr; // Wrong offset
442 }
443 return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
444 }
445
446 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
447 BasicType loadbt, bool is_unsigned_load) {
448 if (!field->is_constant()) {
449 return nullptr; // Non-constant field
622 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
623 ffalse[0] = Type::CONTROL;
624 ffalse[1] = Type::TOP;
625 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
626
627 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
628 fneither[0] = Type::TOP;
629 fneither[1] = Type::TOP;
630 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
631
632 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
633 ftrue[0] = Type::TOP;
634 ftrue[1] = Type::CONTROL;
635 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
636
637 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
638 floop[0] = Type::CONTROL;
639 floop[1] = TypeInt::INT;
640 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
641
642 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
643 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
644 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
645
646 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
647 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
648
649 const Type **fmembar = TypeTuple::fields(0);
650 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
651
652 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
653 fsc[0] = TypeInt::CC;
654 fsc[1] = Type::MEMORY;
655 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
656
657 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
658 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
659 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
660 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
661 false, nullptr, Offset(oopDesc::mark_offset_in_bytes()));
662 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
663 false, nullptr, Offset(oopDesc::klass_offset_in_bytes()));
664 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
665
666 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
667
668 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
669 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
670
671 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
672
673 mreg2type[Op_Node] = Type::BOTTOM;
674 mreg2type[Op_Set ] = nullptr;
675 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
676 mreg2type[Op_RegI] = TypeInt::INT;
677 mreg2type[Op_RegP] = TypePtr::BOTTOM;
678 mreg2type[Op_RegF] = Type::FLOAT;
679 mreg2type[Op_RegD] = Type::DOUBLE;
680 mreg2type[Op_RegL] = TypeLong::LONG;
681 mreg2type[Op_RegFlags] = TypeInt::CC;
682
683 GrowableArray<ciInstanceKlass*> array_interfaces;
684 array_interfaces.push(current->env()->Cloneable_klass());
685 array_interfaces.push(current->env()->Serializable_klass());
686 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
687 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
688
689 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr, false, Offset::bottom);
690 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()));
691
692 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
693
694 #ifdef _LP64
695 if (UseCompressedOops) {
696 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
697 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
698 } else
699 #endif
700 {
701 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
702 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, false, false, false, false, false), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
703 }
704 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_BYTE), true, Offset::bottom);
705 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_SHORT), true, Offset::bottom);
706 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_CHAR), true, Offset::bottom);
707 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_INT), true, Offset::bottom);
708 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_LONG), true, Offset::bottom);
709 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_FLOAT), true, Offset::bottom);
710 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS, false, false, true, true, true), ciTypeArrayKlass::make(T_DOUBLE), true, Offset::bottom);
711 TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true, false, false, false), nullptr, false, Offset::bottom);
712
713 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
714 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
715 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
716 TypeAryPtr::_array_body_type[T_FLAT_ELEMENT] = TypeAryPtr::OOPS;
717 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
718 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
719 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
720 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
721 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
722 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
723 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
724 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
725 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
726
727 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
728 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
729
730 const Type **fi2c = TypeTuple::fields(2);
731 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
732 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
733 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
734
735 const Type **intpair = TypeTuple::fields(2);
736 intpair[0] = TypeInt::INT;
737 intpair[1] = TypeInt::INT;
738 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
739
740 const Type **longpair = TypeTuple::fields(2);
741 longpair[0] = TypeLong::LONG;
742 longpair[1] = TypeLong::LONG;
743 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
744
745 const Type **intccpair = TypeTuple::fields(2);
746 intccpair[0] = TypeInt::INT;
747 intccpair[1] = TypeInt::CC;
748 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
749
750 const Type **longccpair = TypeTuple::fields(2);
751 longccpair[0] = TypeLong::LONG;
752 longccpair[1] = TypeInt::CC;
753 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
754
755 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
756 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
757 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
758 _const_basic_type[T_CHAR] = TypeInt::CHAR;
759 _const_basic_type[T_BYTE] = TypeInt::BYTE;
760 _const_basic_type[T_SHORT] = TypeInt::SHORT;
761 _const_basic_type[T_INT] = TypeInt::INT;
762 _const_basic_type[T_LONG] = TypeLong::LONG;
763 _const_basic_type[T_FLOAT] = Type::FLOAT;
764 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
765 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
766 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
767 _const_basic_type[T_FLAT_ELEMENT] = TypeInstPtr::BOTTOM;
768 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
769 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
770 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
771
772 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
773 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
774 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
775 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
776 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
777 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
778 _zero_type[T_INT] = TypeInt::ZERO;
779 _zero_type[T_LONG] = TypeLong::ZERO;
780 _zero_type[T_FLOAT] = TypeF::ZERO;
781 _zero_type[T_DOUBLE] = TypeD::ZERO;
782 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
783 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
784 _zero_type[T_FLAT_ELEMENT] = TypePtr::NULL_PTR;
785 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
786 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
787
788 // get_zero_type() should not happen for T_CONFLICT
789 _zero_type[T_CONFLICT]= nullptr;
790
791 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
792 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
793
794 if (Matcher::supports_scalable_vector()) {
795 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
796 }
797
798 // Vector predefined types, it needs initialized _const_basic_type[].
799 if (Matcher::vector_size_supported(T_BYTE, 4)) {
800 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
801 }
802 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
803 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
804 }
1039 ~VerifyMeet() {
1040 assert(_C->_type_verify->_depth != 0, "");
1041 _C->_type_verify->_depth--;
1042 if (_C->_type_verify->_depth == 0) {
1043 _C->_type_verify->_cache.trunc_to(0);
1044 }
1045 }
1046
1047 const Type* meet(const Type* t1, const Type* t2) const {
1048 return _C->_type_verify->meet(t1, t2);
1049 }
1050
1051 void add(const Type* t1, const Type* t2, const Type* res) const {
1052 _C->_type_verify->add(t1, t2, res);
1053 }
1054 };
1055
1056 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1057 Compile* C = Compile::current();
1058 const Type* mt2 = verify.meet(t, this);
1059
1060 // Verify that:
1061 // this meet t == t meet this
1062 if (mt != mt2) {
1063 tty->print_cr("=== Meet Not Commutative ===");
1064 tty->print("t = "); t->dump(); tty->cr();
1065 tty->print("this = "); dump(); tty->cr();
1066 tty->print("t meet this = "); mt2->dump(); tty->cr();
1067 tty->print("this meet t = "); mt->dump(); tty->cr();
1068 fatal("meet not commutative");
1069 }
1070 const Type* dual_join = mt->_dual;
1071 const Type* t2t = verify.meet(dual_join,t->_dual);
1072 const Type* t2this = verify.meet(dual_join,this->_dual);
1073
1074 // Interface meet Oop is Not Symmetric:
1075 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1076 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1077
1078 // Verify that:
1079 // 1) mt_dual meet t_dual == t_dual
1080 // which corresponds to
1081 // !(t meet this) meet !t ==
1082 // (!t join !this) meet !t == !t
1083 // 2) mt_dual meet this_dual == this_dual
1084 // which corresponds to
1085 // !(t meet this) meet !this ==
1086 // (!t join !this) meet !this == !this
1087 if (t2t != t->_dual || t2this != this->_dual) {
1088 tty->print_cr("=== Meet Not Symmetric ===");
1089 tty->print("t = "); t->dump(); tty->cr();
1090 tty->print("this= "); dump(); tty->cr();
1091 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
1092
1093 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
1094 tty->print("this_dual= "); _dual->dump(); tty->cr();
1095 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
1096
1097 // 1)
1098 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
1099 // 2)
1100 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1101 tty->cr();
1102 tty->print_cr("Fail: ");
1103 if (t2t != t->_dual) {
1104 tty->print_cr("- mt_dual meet t_dual != t_dual");
1105 }
1106 if (t2this != this->_dual) {
1107 tty->print_cr("- mt_dual meet this_dual != this_dual");
1108 }
1109 tty->cr();
1110
1111 fatal("meet not symmetric");
1112 }
1113 }
1114 #endif
1115
1116 //------------------------------meet-------------------------------------------
1117 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1118 // commutative and the lattice is symmetric.
1119 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1120 if (isa_narrowoop() && t->isa_narrowoop()) {
1121 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1122 return result->make_narrowoop();
1123 }
1124 if (isa_narrowklass() && t->isa_narrowklass()) {
1125 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1126 return result->make_narrowklass();
1127 }
1128
1129 #ifdef ASSERT
1130 Compile* C = Compile::current();
1131 VerifyMeet verify(C);
1132 #endif
1133
1134 const Type *this_t = maybe_remove_speculative(include_speculative);
1135 t = t->maybe_remove_speculative(include_speculative);
1136
1137 const Type *mt = this_t->xmeet(t);
1138 #ifdef ASSERT
1139 verify.add(this_t, t, mt);
1140 if (isa_narrowoop() || t->isa_narrowoop()) {
1141 return mt;
1142 }
1143 if (isa_narrowklass() || t->isa_narrowklass()) {
1144 return mt;
1145 }
1146 // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1147 if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1148 (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1149 this_t->check_symmetrical(t, mt, verify);
1150 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1151 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1152 #endif
1153 return mt;
1154 }
1155
1156 //------------------------------xmeet------------------------------------------
1157 // Compute the MEET of two types. It returns a new Type object.
1158 const Type *Type::xmeet( const Type *t ) const {
1159 // Perform a fast test for common case; meeting the same types together.
1160 if( this == t ) return this; // Meeting same type-rep?
1161
1162 // Meeting TOP with anything?
1163 if( _base == Top ) return t;
1164
1165 // Meeting BOTTOM with anything?
1166 if( _base == Bottom ) return BOTTOM;
1167
1168 // Current "this->_base" is one of: Bad, Multi, Control, Top,
2145 void TypeLong::dump_verbose() const {
2146 TypeIntHelper::int_type_dump(this, tty, true);
2147 }
2148 #endif
2149
2150 //=============================================================================
2151 // Convenience common pre-built types.
2152 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2153 const TypeTuple *TypeTuple::IFFALSE;
2154 const TypeTuple *TypeTuple::IFTRUE;
2155 const TypeTuple *TypeTuple::IFNEITHER;
2156 const TypeTuple *TypeTuple::LOOPBODY;
2157 const TypeTuple *TypeTuple::MEMBAR;
2158 const TypeTuple *TypeTuple::STORECONDITIONAL;
2159 const TypeTuple *TypeTuple::START_I2C;
2160 const TypeTuple *TypeTuple::INT_PAIR;
2161 const TypeTuple *TypeTuple::LONG_PAIR;
2162 const TypeTuple *TypeTuple::INT_CC_PAIR;
2163 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2164
2165 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2166 for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2167 ciField* field = vk->declared_nonstatic_field_at(i);
2168 if (field->is_flat()) {
2169 collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2170 if (!field->is_null_free()) {
2171 // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2172 // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2173 field_array[pos++] = Type::get_const_basic_type(T_INT);
2174 }
2175 } else {
2176 BasicType bt = field->type()->basic_type();
2177 const Type* ft = Type::get_const_type(field->type());
2178 field_array[pos++] = ft;
2179 if (type2size[bt] == 2) {
2180 field_array[pos++] = Type::HALF;
2181 }
2182 }
2183 }
2184 }
2185
2186 //------------------------------make-------------------------------------------
2187 // Make a TypeTuple from the range of a method signature
2188 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2189 ciType* return_type = sig->return_type();
2190 uint arg_cnt = return_type->size();
2191 if (ret_vt_fields) {
2192 arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2193 // InlineTypeNode::NullMarker field used for null checking
2194 arg_cnt++;
2195 }
2196 const Type **field_array = fields(arg_cnt);
2197 switch (return_type->basic_type()) {
2198 case T_LONG:
2199 field_array[TypeFunc::Parms] = TypeLong::LONG;
2200 field_array[TypeFunc::Parms+1] = Type::HALF;
2201 break;
2202 case T_DOUBLE:
2203 field_array[TypeFunc::Parms] = Type::DOUBLE;
2204 field_array[TypeFunc::Parms+1] = Type::HALF;
2205 break;
2206 case T_OBJECT:
2207 if (return_type->is_inlinetype() && ret_vt_fields) {
2208 uint pos = TypeFunc::Parms;
2209 field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2210 collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2211 // InlineTypeNode::NullMarker field used for null checking
2212 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2213 assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2214 break;
2215 } else {
2216 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2217 }
2218 break;
2219 case T_ARRAY:
2220 case T_BOOLEAN:
2221 case T_CHAR:
2222 case T_FLOAT:
2223 case T_BYTE:
2224 case T_SHORT:
2225 case T_INT:
2226 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2227 break;
2228 case T_VOID:
2229 break;
2230 default:
2231 ShouldNotReachHere();
2232 }
2233 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2234 }
2235
2236 // Make a TypeTuple from the domain of a method signature
2237 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2238 ciSignature* sig = method->signature();
2239 uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2240 if (vt_fields_as_args) {
2241 arg_cnt = 0;
2242 assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2243 for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2244 arg_cnt += type2size[(*sig_cc)._bt];
2245 }
2246 }
2247
2248 uint pos = TypeFunc::Parms;
2249 const Type** field_array = fields(arg_cnt);
2250 if (!method->is_static()) {
2251 ciInstanceKlass* recv = method->holder();
2252 if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2253 collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2254 } else {
2255 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2256 }
2257 }
2258
2259 int i = 0;
2260 while (pos < TypeFunc::Parms + arg_cnt) {
2261 ciType* type = sig->type_at(i);
2262 BasicType bt = type->basic_type();
2263
2264 switch (bt) {
2265 case T_LONG:
2266 field_array[pos++] = TypeLong::LONG;
2267 field_array[pos++] = Type::HALF;
2268 break;
2269 case T_DOUBLE:
2270 field_array[pos++] = Type::DOUBLE;
2271 field_array[pos++] = Type::HALF;
2272 break;
2273 case T_OBJECT:
2274 if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2275 // InlineTypeNode::NullMarker field used for null checking
2276 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2277 collect_inline_fields(type->as_inline_klass(), field_array, pos);
2278 } else {
2279 field_array[pos++] = get_const_type(type, interface_handling);
2280 }
2281 break;
2282 case T_ARRAY:
2283 case T_FLOAT:
2284 case T_INT:
2285 field_array[pos++] = get_const_type(type, interface_handling);
2286 break;
2287 case T_BOOLEAN:
2288 case T_CHAR:
2289 case T_BYTE:
2290 case T_SHORT:
2291 field_array[pos++] = TypeInt::INT;
2292 break;
2293 default:
2294 ShouldNotReachHere();
2295 }
2296 i++;
2297 }
2298 assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2299
2300 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2301 }
2302
2303 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2304 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2305 }
2306
2307 //------------------------------fields-----------------------------------------
2308 // Subroutine call type with space allocated for argument types
2309 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2310 const Type **TypeTuple::fields( uint arg_cnt ) {
2311 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2312 flds[TypeFunc::Control ] = Type::CONTROL;
2313 flds[TypeFunc::I_O ] = Type::ABIO;
2314 flds[TypeFunc::Memory ] = Type::MEMORY;
2315 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2316 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2317
2318 return flds;
2413 if (_fields[i]->empty()) return true;
2414 }
2415 return false;
2416 }
2417
2418 //=============================================================================
2419 // Convenience common pre-built types.
2420
2421 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2422 // Certain normalizations keep us sane when comparing types.
2423 // We do not want arrayOop variables to differ only by the wideness
2424 // of their index types. Pick minimum wideness, since that is the
2425 // forced wideness of small ranges anyway.
2426 if (size->_widen != Type::WidenMin)
2427 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2428 else
2429 return size;
2430 }
2431
2432 //------------------------------make-------------------------------------------
2433 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2434 bool flat, bool not_flat, bool not_null_free, bool atomic) {
2435 if (UseCompressedOops && elem->isa_oopptr()) {
2436 elem = elem->make_narrowoop();
2437 }
2438 size = normalize_array_size(size);
2439 return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free, atomic))->hashcons();
2440 }
2441
2442 //------------------------------meet-------------------------------------------
2443 // Compute the MEET of two types. It returns a new Type object.
2444 const Type *TypeAry::xmeet( const Type *t ) const {
2445 // Perform a fast test for common case; meeting the same types together.
2446 if( this == t ) return this; // Meeting same type-rep?
2447
2448 // Current "this->_base" is Ary
2449 switch (t->base()) { // switch on original type
2450
2451 case Bottom: // Ye Olde Default
2452 return t;
2453
2454 default: // All else is a mistake
2455 typerr(t);
2456
2457 case Array: { // Meeting 2 arrays?
2458 const TypeAry* a = t->is_ary();
2459 const Type* size = _size->xmeet(a->_size);
2460 const TypeInt* isize = size->isa_int();
2461 if (isize == nullptr) {
2462 assert(size == Type::TOP || size == Type::BOTTOM, "");
2463 return size;
2464 }
2465 return TypeAry::make(_elem->meet_speculative(a->_elem),
2466 isize, _stable && a->_stable,
2467 _flat && a->_flat,
2468 _not_flat && a->_not_flat,
2469 _not_null_free && a->_not_null_free,
2470 _atomic && a->_atomic);
2471 }
2472 case Top:
2473 break;
2474 }
2475 return this; // Return the double constant
2476 }
2477
2478 //------------------------------xdual------------------------------------------
2479 // Dual: compute field-by-field dual
2480 const Type *TypeAry::xdual() const {
2481 const TypeInt* size_dual = _size->dual()->is_int();
2482 size_dual = normalize_array_size(size_dual);
2483 return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free, !_atomic);
2484 }
2485
2486 //------------------------------eq---------------------------------------------
2487 // Structural equality check for Type representations
2488 bool TypeAry::eq( const Type *t ) const {
2489 const TypeAry *a = (const TypeAry*)t;
2490 return _elem == a->_elem &&
2491 _stable == a->_stable &&
2492 _size == a->_size &&
2493 _flat == a->_flat &&
2494 _not_flat == a->_not_flat &&
2495 _not_null_free == a->_not_null_free &&
2496 _atomic == a->_atomic;
2497
2498 }
2499
2500 //------------------------------hash-------------------------------------------
2501 // Type-specific hashing function.
2502 uint TypeAry::hash(void) const {
2503 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2504 (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0);
2505 }
2506
2507 /**
2508 * Return same type without a speculative part in the element
2509 */
2510 const TypeAry* TypeAry::remove_speculative() const {
2511 return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2512 }
2513
2514 /**
2515 * Return same type with cleaned up speculative part of element
2516 */
2517 const Type* TypeAry::cleanup_speculative() const {
2518 return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2519 }
2520
2521 /**
2522 * Return same type but with a different inline depth (used for speculation)
2523 *
2524 * @param depth depth to meet with
2525 */
2526 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2527 if (!UseInlineDepthForSpeculativeTypes) {
2528 return this;
2529 }
2530 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2531 }
2532
2533 //------------------------------dump2------------------------------------------
2534 #ifndef PRODUCT
2535 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2536 if (_stable) st->print("stable:");
2537 if (_flat) st->print("flat:");
2538 if (Verbose) {
2539 if (_not_flat) st->print("not flat:");
2540 if (_not_null_free) st->print("not null free:");
2541 }
2542 if (_atomic) st->print("atomic:");
2543 _elem->dump2(d, depth, st);
2544 st->print("[");
2545 _size->dump2(d, depth, st);
2546 st->print("]");
2547 }
2548 #endif
2549
2550 //------------------------------singleton--------------------------------------
2551 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2552 // constants (Ldi nodes). Singletons are integer, float or double constants
2553 // or a single symbol.
2554 bool TypeAry::singleton(void) const {
2555 return false; // Never a singleton
2556 }
2557
2558 bool TypeAry::empty(void) const {
2559 return _elem->empty() || _size->empty();
2560 }
2561
2562 //--------------------------ary_must_be_exact----------------------------------
2563 bool TypeAry::ary_must_be_exact() const {
2564 // This logic looks at the element type of an array, and returns true
2565 // if the element type is either a primitive or a final instance class.
2566 // In such cases, an array built on this ary must have no subclasses.
2567 if (_elem == BOTTOM) return false; // general array not exact
2568 if (_elem == TOP ) return false; // inverted general array not exact
2569 const TypeOopPtr* toop = nullptr;
2570 if (UseCompressedOops && _elem->isa_narrowoop()) {
2571 toop = _elem->make_ptr()->isa_oopptr();
2572 } else {
2573 toop = _elem->isa_oopptr();
2574 }
2575 if (!toop) return true; // a primitive type, like int
2576 if (!toop->is_loaded()) return false; // unloaded class
2577 const TypeInstPtr* tinst;
2578 if (_elem->isa_narrowoop())
2579 tinst = _elem->make_ptr()->isa_instptr();
2580 else
2581 tinst = _elem->isa_instptr();
2582 if (tinst) {
2583 if (tinst->instance_klass()->is_final()) {
2584 // Even though MyValue is final, [LMyValue is only exact if the array
2585 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2586 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2587 // If so, we should add '&& !_not_null_free'
2588 if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2589 return false;
2590 }
2591 return true;
2592 }
2593 return false;
2594 }
2595 const TypeAryPtr* tap;
2596 if (_elem->isa_narrowoop())
2597 tap = _elem->make_ptr()->isa_aryptr();
2598 else
2599 tap = _elem->isa_aryptr();
2600 if (tap)
2601 return tap->ary()->ary_must_be_exact();
2602 return false;
2603 }
2604
2605 //==============================TypeVect=======================================
2606 // Convenience common pre-built types.
2607 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2608 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2609 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2610 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2611 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2612 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2613 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2614
2749
2750 //=============================================================================
2751 // Convenience common pre-built types.
2752 const TypePtr *TypePtr::NULL_PTR;
2753 const TypePtr *TypePtr::NOTNULL;
2754 const TypePtr *TypePtr::BOTTOM;
2755
2756 //------------------------------meet-------------------------------------------
2757 // Meet over the PTR enum
2758 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2759 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2760 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2761 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2762 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2763 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2764 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2765 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2766 };
2767
2768 //------------------------------make-------------------------------------------
2769 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2770 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2771 }
2772
2773 //------------------------------cast_to_ptr_type-------------------------------
2774 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2775 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2776 if( ptr == _ptr ) return this;
2777 return make(_base, ptr, _offset, _speculative, _inline_depth);
2778 }
2779
2780 //------------------------------get_con----------------------------------------
2781 intptr_t TypePtr::get_con() const {
2782 assert( _ptr == Null, "" );
2783 return offset();
2784 }
2785
2786 //------------------------------meet-------------------------------------------
2787 // Compute the MEET of two types. It returns a new Type object.
2788 const Type *TypePtr::xmeet(const Type *t) const {
2789 const Type* res = xmeet_helper(t);
2790 if (res->isa_ptr() == nullptr) {
2791 return res;
2792 }
2793
2794 const TypePtr* res_ptr = res->is_ptr();
2795 if (res_ptr->speculative() != nullptr) {
2796 // type->speculative() is null means that speculation is no better
2797 // than type, i.e. type->speculative() == type. So there are 2
2798 // ways to represent the fact that we have no useful speculative
2799 // data and we should use a single one to be able to test for
2800 // equality between types. Check whether type->speculative() ==
2801 // type and set speculative to null if it is the case.
2802 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2803 return res_ptr->remove_speculative();
2837 int depth = meet_inline_depth(tp->inline_depth());
2838 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2839 }
2840 case RawPtr: // For these, flip the call around to cut down
2841 case OopPtr:
2842 case InstPtr: // on the cases I have to handle.
2843 case AryPtr:
2844 case MetadataPtr:
2845 case KlassPtr:
2846 case InstKlassPtr:
2847 case AryKlassPtr:
2848 return t->xmeet(this); // Call in reverse direction
2849 default: // All else is a mistake
2850 typerr(t);
2851
2852 }
2853 return this;
2854 }
2855
2856 //------------------------------meet_offset------------------------------------
2857 Type::Offset TypePtr::meet_offset(int offset) const {
2858 return _offset.meet(Offset(offset));
2859 }
2860
2861 //------------------------------dual_offset------------------------------------
2862 Type::Offset TypePtr::dual_offset() const {
2863 return _offset.dual();
2864 }
2865
2866 //------------------------------xdual------------------------------------------
2867 // Dual: compute field-by-field dual
2868 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2869 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2870 };
2871
2872 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2873 /* TopFlat -> */ MaybeFlat,
2874 /* Flat -> */ NotFlat,
2875 /* NotFlat -> */ Flat,
2876 /* MaybeFlat -> */ TopFlat
2877 };
2878
2879 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2880 "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2881 };
2882
2883 const Type *TypePtr::xdual() const {
2884 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2885 }
2886
2887 //------------------------------xadd_offset------------------------------------
2888 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2889 return _offset.add(offset);
2890 }
2891
2892 //------------------------------add_offset-------------------------------------
2893 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2894 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2895 }
2896
2897 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2898 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2899 }
2900
2901 //------------------------------eq---------------------------------------------
2902 // Structural equality check for Type representations
2903 bool TypePtr::eq( const Type *t ) const {
2904 const TypePtr *a = (const TypePtr*)t;
2905 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2906 }
2907
2908 //------------------------------hash-------------------------------------------
2909 // Type-specific hashing function.
2910 uint TypePtr::hash(void) const {
2911 return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2912 }
2913
2914 /**
2915 * Return same type without a speculative part
2916 */
2917 const TypePtr* TypePtr::remove_speculative() const {
2918 if (_speculative == nullptr) {
2919 return this;
2920 }
2921 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2922 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2923 }
2924
2925 /**
2926 * Return same type but drop speculative part if we know we won't use
2927 * it
2928 */
2929 const Type* TypePtr::cleanup_speculative() const {
2930 if (speculative() == nullptr) {
2931 return this;
3148 return false;
3149 }
3150 // We already know the speculative type cannot be null
3151 if (!speculative_maybe_null()) {
3152 return false;
3153 }
3154 // We already know this is always null
3155 if (this == TypePtr::NULL_PTR) {
3156 return false;
3157 }
3158 // We already know the speculative type is always null
3159 if (speculative_always_null()) {
3160 return false;
3161 }
3162 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3163 return false;
3164 }
3165 return true;
3166 }
3167
3168 TypePtr::FlatInArray TypePtr::compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact) {
3169 if (!instance_klass->can_be_inline_klass(is_exact)) {
3170 // Definitely not a value class and thus never flat in an array.
3171 return NotFlat;
3172 }
3173 if (instance_klass->is_inlinetype() && instance_klass->as_inline_klass()->is_always_flat_in_array()) {
3174 return Flat;
3175 }
3176 // We don't know.
3177 return MaybeFlat;
3178 }
3179
3180 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3181 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3182 FlatInArray old_flat_in_array) const {
3183 switch (old_flat_in_array) {
3184 case Flat:
3185 assert(can_be_inline_type(), "only value objects can be flat in array");
3186 assert(!instance_klass->is_inlinetype() || instance_klass->as_inline_klass()->is_always_flat_in_array(),
3187 "a value object is only marked flat in array if it's proven to be always flat in array");
3188 break;
3189 case NotFlat:
3190 assert(!instance_klass->maybe_flat_in_array(), "cannot be flat");
3191 break;
3192 case MaybeFlat:
3193 return compute_flat_in_array(instance_klass, is_exact);
3194 break;
3195 default:
3196 break;
3197 }
3198 return old_flat_in_array;
3199 }
3200
3201 //------------------------------dump2------------------------------------------
3202 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3203 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3204 };
3205
3206 #ifndef PRODUCT
3207 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3208 st->print("ptr:%s", ptr_msg[_ptr]);
3209 dump_offset(st);
3210 dump_inline_depth(st);
3211 dump_speculative(st);
3212 }
3213
3214 void TypePtr::dump_offset(outputStream* st) const {
3215 _offset.dump2(st);
3216 }
3217
3218 /**
3219 *dump the speculative part of the type
3220 */
3221 void TypePtr::dump_speculative(outputStream *st) const {
3222 if (_speculative != nullptr) {
3223 st->print(" (speculative=");
3224 _speculative->dump_on(st);
3225 st->print(")");
3226 }
3227 }
3228
3229 /**
3230 *dump the inline depth of the type
3231 */
3232 void TypePtr::dump_inline_depth(outputStream *st) const {
3233 if (_inline_depth != InlineDepthBottom) {
3234 if (_inline_depth == InlineDepthTop) {
3235 st->print(" (inline_depth=InlineDepthTop)");
3236 } else {
3237 st->print(" (inline_depth=%d)", _inline_depth);
3238 }
3239 }
3240 }
3241
3242 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3243 switch (flat_in_array) {
3244 case MaybeFlat:
3245 case NotFlat:
3246 if (!Verbose) {
3247 break;
3248 }
3249 case TopFlat:
3250 case Flat:
3251 st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3252 break;
3253 default:
3254 ShouldNotReachHere();
3255 }
3256 }
3257 #endif
3258
3259 //------------------------------singleton--------------------------------------
3260 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3261 // constants
3262 bool TypePtr::singleton(void) const {
3263 // TopPTR, Null, AnyNull, Constant are all singletons
3264 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3265 }
3266
3267 bool TypePtr::empty(void) const {
3268 return (_offset == Offset::top) || above_centerline(_ptr);
3269 }
3270
3271 //=============================================================================
3272 // Convenience common pre-built types.
3273 const TypeRawPtr *TypeRawPtr::BOTTOM;
3274 const TypeRawPtr *TypeRawPtr::NOTNULL;
3275
3276 //------------------------------make-------------------------------------------
3277 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3278 assert( ptr != Constant, "what is the constant?" );
3279 assert( ptr != Null, "Use TypePtr for null" );
3280 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3281 }
3282
3283 const TypeRawPtr *TypeRawPtr::make(address bits) {
3284 assert(bits != nullptr, "Use TypePtr for null");
3285 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3286 }
3287
3288 //------------------------------cast_to_ptr_type-------------------------------
3656 #endif
3657
3658 // Can't be implemented because there's no way to know if the type is above or below the center line.
3659 const Type* TypeInterfaces::xmeet(const Type* t) const {
3660 ShouldNotReachHere();
3661 return Type::xmeet(t);
3662 }
3663
3664 bool TypeInterfaces::singleton(void) const {
3665 ShouldNotReachHere();
3666 return Type::singleton();
3667 }
3668
3669 bool TypeInterfaces::has_non_array_interface() const {
3670 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3671
3672 return !TypeAryPtr::_array_interfaces->contains(this);
3673 }
3674
3675 //------------------------------TypeOopPtr-------------------------------------
3676 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3677 int instance_id, const TypePtr* speculative, int inline_depth)
3678 : TypePtr(t, ptr, offset, speculative, inline_depth),
3679 _const_oop(o), _klass(k),
3680 _interfaces(interfaces),
3681 _klass_is_exact(xk),
3682 _is_ptr_to_narrowoop(false),
3683 _is_ptr_to_narrowklass(false),
3684 _is_ptr_to_boxed_value(false),
3685 _is_ptr_to_strict_final_field(false),
3686 _instance_id(instance_id) {
3687 #ifdef ASSERT
3688 if (klass() != nullptr && klass()->is_loaded()) {
3689 interfaces->verify_is_loaded();
3690 }
3691 #endif
3692 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3693 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3694 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3695 _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3696 }
3697
3698 if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3699 this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3700 ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3701 if (field != nullptr && field->is_strict() && field->is_final()) {
3702 _is_ptr_to_strict_final_field = true;
3703 }
3704 }
3705
3706 #ifdef _LP64
3707 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3708 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3709 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3710 } else if (klass() == nullptr) {
3711 // Array with unknown body type
3712 assert(this->isa_aryptr(), "only arrays without klass");
3713 _is_ptr_to_narrowoop = UseCompressedOops;
3714 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3715 if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3716 // Check if the field of the inline type array element contains oops
3717 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3718 int foffset = field_offset.get() + vk->payload_offset();
3719 BasicType field_bt;
3720 ciField* field = vk->get_field_by_offset(foffset, false);
3721 if (field != nullptr) {
3722 field_bt = field->layout_type();
3723 } else {
3724 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);
3725 field_bt = T_BOOLEAN;
3726 }
3727 _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3728 } else if (klass()->is_obj_array_klass()) {
3729 _is_ptr_to_narrowoop = true;
3730 }
3731 } else if (klass()->is_instance_klass()) {
3732 if (this->isa_klassptr()) {
3733 // Perm objects don't use compressed references
3734 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3735 // unsafe access
3736 _is_ptr_to_narrowoop = UseCompressedOops;
3737 } else {
3738 assert(this->isa_instptr(), "must be an instance ptr.");
3739 if (klass() == ciEnv::current()->Class_klass() &&
3740 (this->offset() == java_lang_Class::klass_offset() ||
3741 this->offset() == java_lang_Class::array_klass_offset())) {
3742 // Special hidden fields from the Class.
3743 assert(this->isa_instptr(), "must be an instance ptr.");
3744 _is_ptr_to_narrowoop = false;
3745 } else if (klass() == ciEnv::current()->Class_klass() &&
3746 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3747 // Static fields
3748 BasicType basic_elem_type = T_ILLEGAL;
3749 if (const_oop() != nullptr) {
3750 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3751 basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3752 }
3753 if (basic_elem_type != T_ILLEGAL) {
3754 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3755 } else {
3756 // unsafe access
3757 _is_ptr_to_narrowoop = UseCompressedOops;
3758 }
3759 } else {
3760 // Instance fields which contains a compressed oop references.
3761 ciInstanceKlass* ik = klass()->as_instance_klass();
3762 BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3763 if (basic_elem_type != T_ILLEGAL) {
3764 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3765 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3766 // Compile::find_alias_type() cast exactness on all types to verify
3767 // that it does not affect alias type.
3768 _is_ptr_to_narrowoop = UseCompressedOops;
3769 } else {
3770 // Type for the copy start in LibraryCallKit::inline_native_clone().
3771 _is_ptr_to_narrowoop = UseCompressedOops;
3772 }
3773 }
3774 }
3775 }
3776 }
3777 #endif // _LP64
3778 }
3779
3780 //------------------------------make-------------------------------------------
3781 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3782 const TypePtr* speculative, int inline_depth) {
3783 assert(ptr != Constant, "no constant generic pointers");
3784 ciKlass* k = Compile::current()->env()->Object_klass();
3785 bool xk = false;
3786 ciObject* o = nullptr;
3787 const TypeInterfaces* interfaces = TypeInterfaces::make();
3788 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3789 }
3790
3791
3792 //------------------------------cast_to_ptr_type-------------------------------
3793 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3794 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3795 if( ptr == _ptr ) return this;
3796 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3797 }
3798
3799 //-----------------------------cast_to_instance_id----------------------------
3800 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3801 // There are no instances of a general oop.
3802 // Return self unchanged.
3803 return this;
3804 }
3805
3806 //-----------------------------cast_to_exactness-------------------------------
3807 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3808 // There is no such thing as an exact general oop.
3809 // Return self unchanged.
3810 return this;
3811 }
3812
3813 //------------------------------as_klass_type----------------------------------
3814 // Return the klass type corresponding to this instance or array type.
3815 // It is the type that is loaded from an object of this type.
3816 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3817 ShouldNotReachHere();
3818 return nullptr;
3819 }
3820
3821 //------------------------------meet-------------------------------------------
3822 // Compute the MEET of two types. It returns a new Type object.
3823 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3824 // Perform a fast test for common case; meeting the same types together.
3825 if( this == t ) return this; // Meeting same type-rep?
3826
3827 // Current "this->_base" is OopPtr
3828 switch (t->base()) { // switch on original type
3829
3830 case Int: // Mixing ints & oops happens when javac
3831 case Long: // reuses local variables
3832 case HalfFloatTop:
3841 case NarrowOop:
3842 case NarrowKlass:
3843 case Bottom: // Ye Olde Default
3844 return Type::BOTTOM;
3845 case Top:
3846 return this;
3847
3848 default: // All else is a mistake
3849 typerr(t);
3850
3851 case RawPtr:
3852 case MetadataPtr:
3853 case KlassPtr:
3854 case InstKlassPtr:
3855 case AryKlassPtr:
3856 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3857
3858 case AnyPtr: {
3859 // Found an AnyPtr type vs self-OopPtr type
3860 const TypePtr *tp = t->is_ptr();
3861 Offset offset = meet_offset(tp->offset());
3862 PTR ptr = meet_ptr(tp->ptr());
3863 const TypePtr* speculative = xmeet_speculative(tp);
3864 int depth = meet_inline_depth(tp->inline_depth());
3865 switch (tp->ptr()) {
3866 case Null:
3867 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3868 // else fall through:
3869 case TopPTR:
3870 case AnyNull: {
3871 int instance_id = meet_instance_id(InstanceTop);
3872 return make(ptr, offset, instance_id, speculative, depth);
3873 }
3874 case BotPTR:
3875 case NotNull:
3876 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3877 default: typerr(t);
3878 }
3879 }
3880
3881 case OopPtr: { // Meeting to other OopPtrs
3883 int instance_id = meet_instance_id(tp->instance_id());
3884 const TypePtr* speculative = xmeet_speculative(tp);
3885 int depth = meet_inline_depth(tp->inline_depth());
3886 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3887 }
3888
3889 case InstPtr: // For these, flip the call around to cut down
3890 case AryPtr:
3891 return t->xmeet(this); // Call in reverse direction
3892
3893 } // End of switch
3894 return this; // Return the double constant
3895 }
3896
3897
3898 //------------------------------xdual------------------------------------------
3899 // Dual of a pure heap pointer. No relevant klass or oop information.
3900 const Type *TypeOopPtr::xdual() const {
3901 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3902 assert(const_oop() == nullptr, "no constants here");
3903 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());
3904 }
3905
3906 //--------------------------make_from_klass_common-----------------------------
3907 // Computes the element-type given a klass.
3908 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3909 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3910 Compile* C = Compile::current();
3911 Dependencies* deps = C->dependencies();
3912 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3913 // Element is an instance
3914 bool klass_is_exact = false;
3915 ciInstanceKlass* ik = klass->as_instance_klass();
3916 if (klass->is_loaded()) {
3917 // Try to set klass_is_exact.
3918 klass_is_exact = ik->is_final();
3919 if (!klass_is_exact && klass_change
3920 && deps != nullptr && UseUniqueSubclasses) {
3921 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3922 if (sub != nullptr) {
3923 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3924 klass = ik = sub;
3925 klass_is_exact = sub->is_final();
3926 }
3927 }
3928 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3929 !ik->is_interface() && !ik->has_subklass()) {
3930 // Add a dependence; if concrete subclass added we need to recompile
3931 deps->assert_leaf_type(ik);
3932 klass_is_exact = true;
3933 }
3934 }
3935 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
3936 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3937 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
3938 } else if (klass->is_obj_array_klass()) {
3939 // Element is an object or inline type array. Recursively call ourself.
3940 ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
3941 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3942 bool xk = array_klass->is_loaded() && array_klass->is_refined();
3943
3944 // Determine null-free/flat properties
3945 bool flat;
3946 bool not_flat;
3947 bool is_null_free;
3948 bool not_null_free;
3949 bool atomic;
3950 if (xk) {
3951 flat = array_klass->is_flat_array_klass();
3952 not_flat = !flat;
3953 is_null_free = array_klass->is_elem_null_free();
3954 not_null_free = !is_null_free;
3955 atomic = array_klass->is_elem_atomic();
3956
3957 if (is_null_free) {
3958 etype = etype->join_speculative(NOTNULL)->is_oopptr();
3959 }
3960 } else {
3961 const TypeOopPtr* exact_etype = etype;
3962 if (etype->can_be_inline_type()) {
3963 // Use exact type if element can be an inline type
3964 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3965 }
3966
3967 flat = false;
3968 bool not_inline = !exact_etype->can_be_inline_type();
3969 not_null_free = not_inline;
3970 not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
3971 atomic = not_flat;
3972 }
3973
3974 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
3975 // We used to pass NotNull in here, asserting that the sub-arrays
3976 // are all not-null. This is not true in generally, as code can
3977 // slam nullptrs down in the subarrays.
3978 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3979 return arr;
3980 } else if (klass->is_type_array_klass()) {
3981 // Element is an typeArray
3982 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3983 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3984 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
3985 // We used to pass NotNull in here, asserting that the array pointer
3986 // is not-null. That was not true in general.
3987 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3988 return arr;
3989 } else {
3990 ShouldNotReachHere();
3991 return nullptr;
3992 }
3993 }
3994
3995 //------------------------------make_from_constant-----------------------------
3996 // Make a java pointer from an oop constant
3997 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3998 assert(!o->is_null_object(), "null object not yet handled here.");
3999
4000 const bool make_constant = require_constant || o->should_be_constant();
4001
4002 ciKlass* klass = o->klass();
4003 if (klass->is_instance_klass() || klass->is_inlinetype()) {
4004 // Element is an instance or inline type
4005 if (make_constant) {
4006 return TypeInstPtr::make(o);
4007 } else {
4008 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4009 }
4010 } else if (klass->is_obj_array_klass()) {
4011 // Element is an object array. Recursively call ourself.
4012 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4013 bool is_flat = o->as_array()->is_flat();
4014 bool is_null_free = o->as_array()->is_null_free();
4015 if (is_null_free) {
4016 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4017 }
4018 bool is_atomic = o->as_array()->is_atomic();
4019 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
4020 /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
4021 // We used to pass NotNull in here, asserting that the sub-arrays
4022 // are all not-null. This is not true in generally, as code can
4023 // slam nulls down in the subarrays.
4024 if (make_constant) {
4025 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4026 } else {
4027 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4028 }
4029 } else if (klass->is_type_array_klass()) {
4030 // Element is an typeArray
4031 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4032 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4033 /* not_flat= */ true, /* not_null_free= */ true, true);
4034 // We used to pass NotNull in here, asserting that the array pointer
4035 // is not-null. That was not true in general.
4036 if (make_constant) {
4037 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4038 } else {
4039 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4040 }
4041 }
4042
4043 fatal("unhandled object type");
4044 return nullptr;
4045 }
4046
4047 //------------------------------get_con----------------------------------------
4048 intptr_t TypeOopPtr::get_con() const {
4049 assert( _ptr == Null || _ptr == Constant, "" );
4050 assert(offset() >= 0, "");
4051
4052 if (offset() != 0) {
4053 // After being ported to the compiler interface, the compiler no longer
4054 // directly manipulates the addresses of oops. Rather, it only has a pointer
4055 // to a handle at compile time. This handle is embedded in the generated
4056 // code and dereferenced at the time the nmethod is made. Until that time,
4057 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4058 // have access to the addresses!). This does not seem to currently happen,
4059 // but this assertion here is to help prevent its occurrence.
4060 tty->print_cr("Found oop constant with non-zero offset");
4061 ShouldNotReachHere();
4062 }
4063
4064 return (intptr_t)const_oop()->constant_encoding();
4065 }
4066
4067
4068 //-----------------------------filter------------------------------------------
4069 // Do not allow interface-vs.-noninterface joins to collapse to top.
4070 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4071
4072 const Type* ft = join_helper(kills, include_speculative);
4118 dump_speculative(st);
4119 }
4120
4121 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4122 if (_instance_id == InstanceTop) {
4123 st->print(",iid=top");
4124 } else if (_instance_id == InstanceBot) {
4125 st->print(",iid=bot");
4126 } else {
4127 st->print(",iid=%d", _instance_id);
4128 }
4129 }
4130 #endif
4131
4132 //------------------------------singleton--------------------------------------
4133 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4134 // constants
4135 bool TypeOopPtr::singleton(void) const {
4136 // detune optimizer to not generate constant oop + constant offset as a constant!
4137 // TopPTR, Null, AnyNull, Constant are all singletons
4138 return (offset() == 0) && !below_centerline(_ptr);
4139 }
4140
4141 //------------------------------add_offset-------------------------------------
4142 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4143 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4144 }
4145
4146 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4147 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4148 }
4149
4150 /**
4151 * Return same type without a speculative part
4152 */
4153 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4154 if (_speculative == nullptr) {
4155 return this;
4156 }
4157 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4158 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4159 }
4160
4161 /**
4162 * Return same type but drop speculative part if we know we won't use
4163 * it
4164 */
4165 const Type* TypeOopPtr::cleanup_speculative() const {
4166 // If the klass is exact and the ptr is not null then there's
4167 // nothing that the speculative type can help us with
4240 const TypeInstPtr *TypeInstPtr::BOTTOM;
4241 const TypeInstPtr *TypeInstPtr::MIRROR;
4242 const TypeInstPtr *TypeInstPtr::MARK;
4243 const TypeInstPtr *TypeInstPtr::KLASS;
4244
4245 // Is there a single ciKlass* that can represent that type?
4246 ciKlass* TypeInstPtr::exact_klass_helper() const {
4247 if (_interfaces->empty()) {
4248 return _klass;
4249 }
4250 if (_klass != ciEnv::current()->Object_klass()) {
4251 if (_interfaces->eq(_klass->as_instance_klass())) {
4252 return _klass;
4253 }
4254 return nullptr;
4255 }
4256 return _interfaces->exact_klass();
4257 }
4258
4259 //------------------------------TypeInstPtr-------------------------------------
4260 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4261 FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4262 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4263 _flat_in_array(flat_in_array) {
4264
4265 assert(flat_in_array != Uninitialized, "must be set now");
4266 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4267 assert(k != nullptr &&
4268 (k->is_loaded() || o == nullptr),
4269 "cannot have constants with non-loaded klass");
4270 };
4271
4272 //------------------------------make-------------------------------------------
4273 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4274 ciKlass* k,
4275 const TypeInterfaces* interfaces,
4276 bool xk,
4277 ciObject* o,
4278 Offset offset,
4279 FlatInArray flat_in_array,
4280 int instance_id,
4281 const TypePtr* speculative,
4282 int inline_depth) {
4283 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4284 // Either const_oop() is null or else ptr is Constant
4285 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4286 "constant pointers must have a value supplied" );
4287 // Ptr is never Null
4288 assert( ptr != Null, "null pointers are not typed" );
4289
4290 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4291 ciInstanceKlass* ik = k->as_instance_klass();
4292 if (ptr == Constant) {
4293 // Note: This case includes meta-object constants, such as methods.
4294 xk = true;
4295 } else if (k->is_loaded()) {
4296 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4297 assert(!ik->is_interface(), "no interface here");
4298 if (xk && ik->is_interface()) xk = false; // no exact interface
4299 }
4300
4301 if (flat_in_array == Uninitialized) {
4302 flat_in_array = compute_flat_in_array(ik, xk);
4303 }
4304 // Now hash this baby
4305 TypeInstPtr *result =
4306 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4307
4308 return result;
4309 }
4310
4311 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4312 if (k->is_instance_klass()) {
4313 if (k->is_loaded()) {
4314 if (k->is_interface() && interface_handling == ignore_interfaces) {
4315 assert(interface, "no interface expected");
4316 k = ciEnv::current()->Object_klass();
4317 const TypeInterfaces* interfaces = TypeInterfaces::make();
4318 return interfaces;
4319 }
4320 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4321 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4322 if (k->is_interface()) {
4323 assert(interface, "no interface expected");
4324 k = ciEnv::current()->Object_klass();
4325 } else {
4326 assert(klass, "no instance klass expected");
4352 switch (bt) {
4353 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4354 case T_INT: return TypeInt::make(constant.as_int());
4355 case T_CHAR: return TypeInt::make(constant.as_char());
4356 case T_BYTE: return TypeInt::make(constant.as_byte());
4357 case T_SHORT: return TypeInt::make(constant.as_short());
4358 case T_FLOAT: return TypeF::make(constant.as_float());
4359 case T_DOUBLE: return TypeD::make(constant.as_double());
4360 case T_LONG: return TypeLong::make(constant.as_long());
4361 default: break;
4362 }
4363 fatal("Invalid boxed value type '%s'", type2name(bt));
4364 return nullptr;
4365 }
4366
4367 //------------------------------cast_to_ptr_type-------------------------------
4368 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4369 if( ptr == _ptr ) return this;
4370 // Reconstruct _sig info here since not a problem with later lazy
4371 // construction, _sig will show up on demand.
4372 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4373 }
4374
4375
4376 //-----------------------------cast_to_exactness-------------------------------
4377 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4378 if( klass_is_exact == _klass_is_exact ) return this;
4379 if (!_klass->is_loaded()) return this;
4380 ciInstanceKlass* ik = _klass->as_instance_klass();
4381 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4382 assert(!ik->is_interface(), "no interface here");
4383 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4384 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4385 }
4386
4387 //-----------------------------cast_to_instance_id----------------------------
4388 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4389 if( instance_id == _instance_id ) return this;
4390 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4391 }
4392
4393 //------------------------------xmeet_unloaded---------------------------------
4394 // Compute the MEET of two InstPtrs when at least one is unloaded.
4395 // Assume classes are different since called after check for same name/class-loader
4396 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4397 Offset off = meet_offset(tinst->offset());
4398 PTR ptr = meet_ptr(tinst->ptr());
4399 int instance_id = meet_instance_id(tinst->instance_id());
4400 const TypePtr* speculative = xmeet_speculative(tinst);
4401 int depth = meet_inline_depth(tinst->inline_depth());
4402
4403 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4404 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4405 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4406 //
4407 // Meet unloaded class with java/lang/Object
4408 //
4409 // Meet
4410 // | Unloaded Class
4411 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4412 // ===================================================================
4413 // TOP | ..........................Unloaded......................|
4414 // AnyNull | U-AN |................Unloaded......................|
4415 // Constant | ... O-NN .................................. | O-BOT |
4416 // NotNull | ... O-NN .................................. | O-BOT |
4417 // BOTTOM | ........................Object-BOTTOM ..................|
4418 //
4419 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4420 //
4421 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4422 else if (loaded->ptr() == TypePtr::AnyNull) {
4423 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4424 return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4425 speculative, depth);
4426 }
4427 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4428 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4429 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4430 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4431 }
4432 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4433
4434 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4435 }
4436
4437 // Both are unloaded, not the same class, not Object
4438 // Or meet unloaded with a different loaded class, not java/lang/Object
4439 if (ptr != TypePtr::BotPTR) {
4440 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4441 }
4442 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4443 }
4444
4445
4446 //------------------------------meet-------------------------------------------
4470 case Top:
4471 return this;
4472
4473 default: // All else is a mistake
4474 typerr(t);
4475
4476 case MetadataPtr:
4477 case KlassPtr:
4478 case InstKlassPtr:
4479 case AryKlassPtr:
4480 case RawPtr: return TypePtr::BOTTOM;
4481
4482 case AryPtr: { // All arrays inherit from Object class
4483 // Call in reverse direction to avoid duplication
4484 return t->is_aryptr()->xmeet_helper(this);
4485 }
4486
4487 case OopPtr: { // Meeting to OopPtrs
4488 // Found a OopPtr type vs self-InstPtr type
4489 const TypeOopPtr *tp = t->is_oopptr();
4490 Offset offset = meet_offset(tp->offset());
4491 PTR ptr = meet_ptr(tp->ptr());
4492 switch (tp->ptr()) {
4493 case TopPTR:
4494 case AnyNull: {
4495 int instance_id = meet_instance_id(InstanceTop);
4496 const TypePtr* speculative = xmeet_speculative(tp);
4497 int depth = meet_inline_depth(tp->inline_depth());
4498 return make(ptr, klass(), _interfaces, klass_is_exact(),
4499 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4500 }
4501 case NotNull:
4502 case BotPTR: {
4503 int instance_id = meet_instance_id(tp->instance_id());
4504 const TypePtr* speculative = xmeet_speculative(tp);
4505 int depth = meet_inline_depth(tp->inline_depth());
4506 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4507 }
4508 default: typerr(t);
4509 }
4510 }
4511
4512 case AnyPtr: { // Meeting to AnyPtrs
4513 // Found an AnyPtr type vs self-InstPtr type
4514 const TypePtr *tp = t->is_ptr();
4515 Offset offset = meet_offset(tp->offset());
4516 PTR ptr = meet_ptr(tp->ptr());
4517 int instance_id = meet_instance_id(InstanceTop);
4518 const TypePtr* speculative = xmeet_speculative(tp);
4519 int depth = meet_inline_depth(tp->inline_depth());
4520 switch (tp->ptr()) {
4521 case Null:
4522 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4523 // else fall through to AnyNull
4524 case TopPTR:
4525 case AnyNull: {
4526 return make(ptr, klass(), _interfaces, klass_is_exact(),
4527 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4528 }
4529 case NotNull:
4530 case BotPTR:
4531 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4532 default: typerr(t);
4533 }
4534 }
4535
4536 /*
4537 A-top }
4538 / | \ } Tops
4539 B-top A-any C-top }
4540 | / | \ | } Any-nulls
4541 B-any | C-any }
4542 | | |
4543 B-con A-con C-con } constants; not comparable across classes
4544 | | |
4545 B-not | C-not }
4546 | \ | / | } not-nulls
4547 B-bot A-not C-bot }
4548 \ | / } Bottoms
4549 A-bot }
4550 */
4551
4552 case InstPtr: { // Meeting 2 Oops?
4553 // Found an InstPtr sub-type vs self-InstPtr type
4554 const TypeInstPtr *tinst = t->is_instptr();
4555 Offset off = meet_offset(tinst->offset());
4556 PTR ptr = meet_ptr(tinst->ptr());
4557 int instance_id = meet_instance_id(tinst->instance_id());
4558 const TypePtr* speculative = xmeet_speculative(tinst);
4559 int depth = meet_inline_depth(tinst->inline_depth());
4560 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4561
4562 ciKlass* tinst_klass = tinst->klass();
4563 ciKlass* this_klass = klass();
4564
4565 ciKlass* res_klass = nullptr;
4566 bool res_xk = false;
4567 const Type* res;
4568 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4569
4570 if (kind == UNLOADED) {
4571 // One of these classes has not been loaded
4572 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4573 #ifndef PRODUCT
4574 if (PrintOpto && Verbose) {
4575 tty->print("meet of unloaded classes resulted in: ");
4576 unloaded_meet->dump();
4577 tty->cr();
4578 tty->print(" this == ");
4579 dump();
4580 tty->cr();
4581 tty->print(" tinst == ");
4582 tinst->dump();
4583 tty->cr();
4584 }
4585 #endif
4586 res = unloaded_meet;
4587 } else {
4588 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4589 if (kind == NOT_SUBTYPE && instance_id > 0) {
4590 instance_id = InstanceBot;
4591 } else if (kind == LCA) {
4592 instance_id = InstanceBot;
4593 }
4594 ciObject* o = nullptr; // Assume not constant when done
4595 ciObject* this_oop = const_oop();
4596 ciObject* tinst_oop = tinst->const_oop();
4597 if (ptr == Constant) {
4598 if (this_oop != nullptr && tinst_oop != nullptr &&
4599 this_oop->equals(tinst_oop))
4600 o = this_oop;
4601 else if (above_centerline(_ptr)) {
4602 assert(!tinst_klass->is_interface(), "");
4603 o = tinst_oop;
4604 } else if (above_centerline(tinst->_ptr)) {
4605 assert(!this_klass->is_interface(), "");
4606 o = this_oop;
4607 } else
4608 ptr = NotNull;
4609 }
4610 res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4611 }
4612
4613 return res;
4614
4615 } // End of case InstPtr
4616
4617 } // End of switch
4618 return this; // Return the double constant
4619 }
4620
4621 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4622 ciKlass*& res_klass, bool& res_xk) {
4623 ciKlass* this_klass = this_type->klass();
4624 ciKlass* other_klass = other_type->klass();
4625
4626 bool this_xk = this_type->klass_is_exact();
4627 bool other_xk = other_type->klass_is_exact();
4628 PTR this_ptr = this_type->ptr();
4629 PTR other_ptr = other_type->ptr();
4630 const TypeInterfaces* this_interfaces = this_type->interfaces();
4631 const TypeInterfaces* other_interfaces = other_type->interfaces();
4632 // Check for easy case; klasses are equal (and perhaps not loaded!)
4633 // If we have constants, then we created oops so classes are loaded
4634 // and we can handle the constants further down. This case handles
4635 // both-not-loaded or both-loaded classes
4636 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4637 res_klass = this_klass;
4638 res_xk = this_xk;
4639 return QUICK;
4640 }
4641
4642 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4643 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4644 return UNLOADED;
4645 }
4651 // If both are up and they do NOT subtype, "fall hard".
4652 // If both are down and they subtype, take the supertype class.
4653 // If both are down and they do NOT subtype, "fall hard".
4654 // Constants treated as down.
4655
4656 // Now, reorder the above list; observe that both-down+subtype is also
4657 // "fall hard"; "fall hard" becomes the default case:
4658 // If we split one up & one down AND they subtype, take the down man.
4659 // If both are up and they subtype, take the subtype class.
4660
4661 // If both are down and they subtype, "fall hard".
4662 // If both are down and they do NOT subtype, "fall hard".
4663 // If both are up and they do NOT subtype, "fall hard".
4664 // If we split one up & one down AND they do NOT subtype, "fall hard".
4665
4666 // If a proper subtype is exact, and we return it, we return it exactly.
4667 // If a proper supertype is exact, there can be no subtyping relationship!
4668 // If both types are equal to the subtype, exactness is and-ed below the
4669 // centerline and or-ed above it. (N.B. Constants are always exact.)
4670
4671 const T* subtype = nullptr;
4672 bool subtype_exact = false;
4673 if (this_type->is_same_java_type_as(other_type)) {
4674 // Same klass
4675 subtype = this_type;
4676 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4677 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4678 subtype = this_type; // Pick subtyping class
4679 subtype_exact = this_xk;
4680 } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4681 subtype = other_type; // Pick subtyping class
4682 subtype_exact = other_xk;
4683 }
4684
4685 if (subtype != nullptr) {
4686 if (above_centerline(ptr)) {
4687 // Both types are empty.
4688 this_type = other_type = subtype;
4689 this_xk = other_xk = subtype_exact;
4690 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4691 // this_type is empty while other_type is not. Take other_type.
4692 this_type = other_type;
4693 this_xk = other_xk;
4694 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4695 // other_type is empty while this_type is not. Take this_type.
4696 other_type = this_type; // this is down; keep down man
4697 } else {
4698 // this_type and other_type are both non-empty.
4699 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4700 }
4701 }
4702
4703 // Check for classes now being equal
4704 if (this_type->is_same_java_type_as(other_type)) {
4705 // If the klasses are equal, the constants may still differ. Fall to
4706 // NotNull if they do (neither constant is null; that is a special case
4707 // handled elsewhere).
4708 res_klass = this_type->klass();
4709 res_xk = this_xk;
4710 return SUBTYPE;
4711 } // Else classes are not equal
4712
4713 // Since klasses are different, we require a LCA in the Java
4714 // class hierarchy - which means we have to fall to at least NotNull.
4715 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4716 ptr = NotNull;
4717 }
4718
4719 interfaces = this_interfaces->intersection_with(other_interfaces);
4720
4721 // Now we find the LCA of Java classes
4722 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4723
4724 res_klass = k;
4725 res_xk = false;
4726 return LCA;
4727 }
4728
4729 // Top-Flat Flat Not-Flat Maybe-Flat
4730 // -------------------------------------------------------------
4731 // Top-Flat Top-Flat Flat Not-Flat Maybe-Flat
4732 // Flat Flat Flat Maybe-Flat Maybe-Flat
4733 // Not-Flat Not-Flat Maybe-Flat Not-Flat Maybe-Flat
4734 // Maybe-Flat Maybe-Flat Maybe-Flat Maybe-Flat Maybe-flat
4735 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4736 if (left == TopFlat) {
4737 return right;
4738 }
4739 if (right == TopFlat) {
4740 return left;
4741 }
4742 if (left == MaybeFlat || right == MaybeFlat) {
4743 return MaybeFlat;
4744 }
4745
4746 switch (left) {
4747 case Flat:
4748 if (right == Flat) {
4749 return Flat;
4750 }
4751 return MaybeFlat;
4752 case NotFlat:
4753 if (right == NotFlat) {
4754 return NotFlat;
4755 }
4756 return MaybeFlat;
4757 default:
4758 ShouldNotReachHere();
4759 return Uninitialized;
4760 }
4761 }
4762
4763 //------------------------java_mirror_type--------------------------------------
4764 ciType* TypeInstPtr::java_mirror_type() const {
4765 // must be a singleton type
4766 if( const_oop() == nullptr ) return nullptr;
4767
4768 // must be of type java.lang.Class
4769 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4770 return const_oop()->as_instance()->java_mirror_type();
4771 }
4772
4773
4774 //------------------------------xdual------------------------------------------
4775 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4776 // inheritance mechanism.
4777 const Type* TypeInstPtr::xdual() const {
4778 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4779 dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4780 }
4781
4782 //------------------------------eq---------------------------------------------
4783 // Structural equality check for Type representations
4784 bool TypeInstPtr::eq( const Type *t ) const {
4785 const TypeInstPtr *p = t->is_instptr();
4786 return
4787 klass()->equals(p->klass()) &&
4788 _flat_in_array == p->_flat_in_array &&
4789 _interfaces->eq(p->_interfaces) &&
4790 TypeOopPtr::eq(p); // Check sub-type stuff
4791 }
4792
4793 //------------------------------hash-------------------------------------------
4794 // Type-specific hashing function.
4795 uint TypeInstPtr::hash() const {
4796 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4797 }
4798
4799 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4800 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4801 }
4802
4803
4804 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4805 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4806 }
4807
4808 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4809 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4810 }
4811
4812
4813 //------------------------------dump2------------------------------------------
4814 // Dump oop Type
4815 #ifndef PRODUCT
4816 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4820 _interfaces->dump(st);
4821
4822 if (_ptr == Constant && (WizardMode || Verbose)) {
4823 ResourceMark rm;
4824 stringStream ss;
4825
4826 st->print(" ");
4827 const_oop()->print_oop(&ss);
4828 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4829 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4830 char* buf = ss.as_string(/* c_heap= */false);
4831 StringUtils::replace_no_expand(buf, "\n", "");
4832 st->print_raw(buf);
4833 }
4834
4835 st->print(":%s", ptr_msg[_ptr]);
4836 if (_klass_is_exact) {
4837 st->print(":exact");
4838 }
4839
4840 st->print(" *");
4841
4842 dump_offset(st);
4843 dump_instance_id(st);
4844 dump_inline_depth(st);
4845 dump_speculative(st);
4846 dump_flat_in_array(_flat_in_array, st);
4847 }
4848 #endif
4849
4850 bool TypeInstPtr::empty() const {
4851 if (_flat_in_array == TopFlat) {
4852 return true;
4853 }
4854 return TypeOopPtr::empty();
4855 }
4856
4857 //------------------------------add_offset-------------------------------------
4858 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4859 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4860 _instance_id, add_offset_speculative(offset), _inline_depth);
4861 }
4862
4863 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4864 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4865 _instance_id, with_offset_speculative(offset), _inline_depth);
4866 }
4867
4868 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4869 if (_speculative == nullptr) {
4870 return this;
4871 }
4872 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4873 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4874 _instance_id, nullptr, _inline_depth);
4875 }
4876
4877 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4878 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4879 }
4880
4881 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4882 if (!UseInlineDepthForSpeculativeTypes) {
4883 return this;
4884 }
4885 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4886 }
4887
4888 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4889 assert(is_known_instance(), "should be known");
4890 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4891 }
4892
4893 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4894 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4895 }
4896
4897 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4898 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4899 }
4900
4901 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4902 bool xk = klass_is_exact();
4903 ciInstanceKlass* ik = klass()->as_instance_klass();
4904 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4905 if (_interfaces->eq(ik)) {
4906 Compile* C = Compile::current();
4907 Dependencies* deps = C->dependencies();
4908 deps->assert_leaf_type(ik);
4909 xk = true;
4910 }
4911 }
4912 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4913 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4914 }
4915
4916 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) {
4917 static_assert(std::is_base_of<T2, T1>::value, "");
4918
4919 if (!this_one->is_instance_type(other)) {
4920 return false;
4921 }
4922
4923 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4924 return true;
4925 }
4926
4927 return this_one->klass()->is_subtype_of(other->klass()) &&
4928 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4929 }
4930
4931
4932 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4933 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4938 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4939 return true;
4940 }
4941
4942 if (this_one->is_instance_type(other)) {
4943 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4944 }
4945
4946 int dummy;
4947 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4948 if (this_top_or_bottom) {
4949 return false;
4950 }
4951
4952 const T1* other_ary = this_one->is_array_type(other);
4953 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4954 const TypePtr* this_elem = this_one->elem()->make_ptr();
4955 if (other_elem != nullptr && this_elem != nullptr) {
4956 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4957 }
4958 if (other_elem == nullptr && this_elem == nullptr) {
4959 return this_one->klass()->is_subtype_of(other->klass());
4960 }
4961
4962 return false;
4963 }
4964
4965 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4966 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4967 }
4968
4969 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4970 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4971 }
4972
4973 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4974 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4975 }
4976
4977 //=============================================================================
4978 // Convenience common pre-built types.
4979 const TypeAryPtr* TypeAryPtr::BOTTOM;
4980 const TypeAryPtr *TypeAryPtr::RANGE;
4981 const TypeAryPtr *TypeAryPtr::OOPS;
4982 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4983 const TypeAryPtr *TypeAryPtr::BYTES;
4984 const TypeAryPtr *TypeAryPtr::SHORTS;
4985 const TypeAryPtr *TypeAryPtr::CHARS;
4986 const TypeAryPtr *TypeAryPtr::INTS;
4987 const TypeAryPtr *TypeAryPtr::LONGS;
4988 const TypeAryPtr *TypeAryPtr::FLOATS;
4989 const TypeAryPtr *TypeAryPtr::DOUBLES;
4990 const TypeAryPtr *TypeAryPtr::INLINES;
4991
4992 //------------------------------make-------------------------------------------
4993 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4994 int instance_id, const TypePtr* speculative, int inline_depth) {
4995 assert(!(k == nullptr && ary->_elem->isa_int()),
4996 "integral arrays must be pre-equipped with a class");
4997 if (!xk) xk = ary->ary_must_be_exact();
4998 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4999 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5000 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5001 k = nullptr;
5002 }
5003 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5004 }
5005
5006 //------------------------------make-------------------------------------------
5007 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5008 int instance_id, const TypePtr* speculative, int inline_depth,
5009 bool is_autobox_cache) {
5010 assert(!(k == nullptr && ary->_elem->isa_int()),
5011 "integral arrays must be pre-equipped with a class");
5012 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5013 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
5014 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5015 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5016 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5017 k = nullptr;
5018 }
5019 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5020 }
5021
5022 //------------------------------cast_to_ptr_type-------------------------------
5023 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5024 if( ptr == _ptr ) return this;
5025 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5026 }
5027
5028
5029 //-----------------------------cast_to_exactness-------------------------------
5030 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5031 if( klass_is_exact == _klass_is_exact ) return this;
5032 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
5033 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5034 }
5035
5036 //-----------------------------cast_to_instance_id----------------------------
5037 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5038 if( instance_id == _instance_id ) return this;
5039 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5040 }
5041
5042
5043 //-----------------------------max_array_length-------------------------------
5044 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5045 jint TypeAryPtr::max_array_length(BasicType etype) {
5046 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5047 if (etype == T_NARROWOOP) {
5048 etype = T_OBJECT;
5049 } else if (etype == T_ILLEGAL) { // bottom[]
5050 etype = T_BYTE; // will produce conservatively high value
5051 } else {
5052 fatal("not an element type: %s", type2name(etype));
5053 }
5054 }
5055 return arrayOopDesc::max_array_length(etype);
5056 }
5057
5058 //-----------------------------narrow_size_type-------------------------------
5059 // Narrow the given size type to the index range for the given array base type.
5077 if (size->is_con()) {
5078 lo = hi;
5079 }
5080 chg = true;
5081 }
5082 // Negative length arrays will produce weird intermediate dead fast-path code
5083 if (lo > hi) {
5084 return TypeInt::ZERO;
5085 }
5086 if (!chg) {
5087 return size;
5088 }
5089 return TypeInt::make(lo, hi, Type::WidenMin);
5090 }
5091
5092 //-------------------------------cast_to_size----------------------------------
5093 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5094 assert(new_size != nullptr, "");
5095 new_size = narrow_size_type(new_size);
5096 if (new_size == size()) return this;
5097 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5098 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5099 }
5100
5101 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5102 if (flat == is_flat()) {
5103 return this;
5104 }
5105 assert(!flat || !is_not_flat(), "inconsistency");
5106 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5107 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5108 if (res->speculative() == res->remove_speculative()) {
5109 return res->remove_speculative();
5110 }
5111 return res;
5112 }
5113
5114 //-------------------------------cast_to_not_flat------------------------------
5115 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5116 if (not_flat == is_not_flat()) {
5117 return this;
5118 }
5119 assert(!not_flat || !is_flat(), "inconsistency");
5120 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5121 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5122 // We keep the speculative part if it contains information about flat-/nullability.
5123 // Make sure it's removed if it's not better than the non-speculative type anymore.
5124 if (res->speculative() == res->remove_speculative()) {
5125 return res->remove_speculative();
5126 }
5127 return res;
5128 }
5129
5130 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5131 if (null_free == is_null_free()) {
5132 return this;
5133 }
5134 assert(!null_free || !is_not_null_free(), "inconsistency");
5135 const Type* elem = this->elem();
5136 const Type* new_elem = elem->make_ptr();
5137 if (null_free) {
5138 new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5139 } else {
5140 new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5141 }
5142 new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5143 const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5144 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5145 if (res->speculative() == res->remove_speculative()) {
5146 return res->remove_speculative();
5147 }
5148 return res;
5149 }
5150
5151 //-------------------------------cast_to_not_null_free-------------------------
5152 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5153 if (not_null_free == is_not_null_free()) {
5154 return this;
5155 }
5156 assert(!not_null_free || !is_null_free(), "inconsistency");
5157 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5158 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5159 _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5160 // We keep the speculative part if it contains information about flat-/nullability.
5161 // Make sure it's removed if it's not better than the non-speculative type anymore.
5162 if (res->speculative() == res->remove_speculative()) {
5163 return res->remove_speculative();
5164 }
5165 return res;
5166 }
5167
5168 //---------------------------------update_properties---------------------------
5169 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5170 if ((from->is_flat() && is_not_flat()) ||
5171 (from->is_not_flat() && is_flat()) ||
5172 (from->is_null_free() && is_not_null_free()) ||
5173 (from->is_not_null_free() && is_null_free())) {
5174 return nullptr; // Inconsistent properties
5175 }
5176 const TypeAryPtr* res = this;
5177 if (from->is_not_null_free()) {
5178 res = res->cast_to_not_null_free();
5179 }
5180 if (from->is_not_flat()) {
5181 res = res->cast_to_not_flat();
5182 }
5183 return res;
5184 }
5185
5186 jint TypeAryPtr::flat_layout_helper() const {
5187 return exact_klass()->as_flat_array_klass()->layout_helper();
5188 }
5189
5190 int TypeAryPtr::flat_elem_size() const {
5191 return exact_klass()->as_flat_array_klass()->element_byte_size();
5192 }
5193
5194 int TypeAryPtr::flat_log_elem_size() const {
5195 return exact_klass()->as_flat_array_klass()->log2_element_size();
5196 }
5197
5198 //------------------------------cast_to_stable---------------------------------
5199 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5200 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5201 return this;
5202
5203 const Type* elem = this->elem();
5204 const TypePtr* elem_ptr = elem->make_ptr();
5205
5206 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5207 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5208 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5209 }
5210
5211 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5212
5213 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5214 }
5215
5216 //-----------------------------stable_dimension--------------------------------
5217 int TypeAryPtr::stable_dimension() const {
5218 if (!is_stable()) return 0;
5219 int dim = 1;
5220 const TypePtr* elem_ptr = elem()->make_ptr();
5221 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5222 dim += elem_ptr->is_aryptr()->stable_dimension();
5223 return dim;
5224 }
5225
5226 //----------------------cast_to_autobox_cache-----------------------------------
5227 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5228 if (is_autobox_cache()) return this;
5229 const TypeOopPtr* etype = elem()->make_oopptr();
5230 if (etype == nullptr) return this;
5231 // The pointers in the autobox arrays are always non-null.
5232 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5233 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5234 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5235 }
5236
5237 //------------------------------eq---------------------------------------------
5238 // Structural equality check for Type representations
5239 bool TypeAryPtr::eq( const Type *t ) const {
5240 const TypeAryPtr *p = t->is_aryptr();
5241 return
5242 _ary == p->_ary && // Check array
5243 TypeOopPtr::eq(p) &&// Check sub-parts
5244 _field_offset == p->_field_offset;
5245 }
5246
5247 //------------------------------hash-------------------------------------------
5248 // Type-specific hashing function.
5249 uint TypeAryPtr::hash(void) const {
5250 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5251 }
5252
5253 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5254 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5255 }
5256
5257 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5258 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5259 }
5260
5261 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5262 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5263 }
5264 //------------------------------meet-------------------------------------------
5265 // Compute the MEET of two types. It returns a new Type object.
5266 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5267 // Perform a fast test for common case; meeting the same types together.
5268 if( this == t ) return this; // Meeting same type-rep?
5269 // Current "this->_base" is Pointer
5270 switch (t->base()) { // switch on original type
5277 case HalfFloatBot:
5278 case FloatTop:
5279 case FloatCon:
5280 case FloatBot:
5281 case DoubleTop:
5282 case DoubleCon:
5283 case DoubleBot:
5284 case NarrowOop:
5285 case NarrowKlass:
5286 case Bottom: // Ye Olde Default
5287 return Type::BOTTOM;
5288 case Top:
5289 return this;
5290
5291 default: // All else is a mistake
5292 typerr(t);
5293
5294 case OopPtr: { // Meeting to OopPtrs
5295 // Found a OopPtr type vs self-AryPtr type
5296 const TypeOopPtr *tp = t->is_oopptr();
5297 Offset offset = meet_offset(tp->offset());
5298 PTR ptr = meet_ptr(tp->ptr());
5299 int depth = meet_inline_depth(tp->inline_depth());
5300 const TypePtr* speculative = xmeet_speculative(tp);
5301 switch (tp->ptr()) {
5302 case TopPTR:
5303 case AnyNull: {
5304 int instance_id = meet_instance_id(InstanceTop);
5305 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5306 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5307 }
5308 case BotPTR:
5309 case NotNull: {
5310 int instance_id = meet_instance_id(tp->instance_id());
5311 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5312 }
5313 default: ShouldNotReachHere();
5314 }
5315 }
5316
5317 case AnyPtr: { // Meeting two AnyPtrs
5318 // Found an AnyPtr type vs self-AryPtr type
5319 const TypePtr *tp = t->is_ptr();
5320 Offset offset = meet_offset(tp->offset());
5321 PTR ptr = meet_ptr(tp->ptr());
5322 const TypePtr* speculative = xmeet_speculative(tp);
5323 int depth = meet_inline_depth(tp->inline_depth());
5324 switch (tp->ptr()) {
5325 case TopPTR:
5326 return this;
5327 case BotPTR:
5328 case NotNull:
5329 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5330 case Null:
5331 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5332 // else fall through to AnyNull
5333 case AnyNull: {
5334 int instance_id = meet_instance_id(InstanceTop);
5335 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5336 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5337 }
5338 default: ShouldNotReachHere();
5339 }
5340 }
5341
5342 case MetadataPtr:
5343 case KlassPtr:
5344 case InstKlassPtr:
5345 case AryKlassPtr:
5346 case RawPtr: return TypePtr::BOTTOM;
5347
5348 case AryPtr: { // Meeting 2 references?
5349 const TypeAryPtr *tap = t->is_aryptr();
5350 Offset off = meet_offset(tap->offset());
5351 Offset field_off = meet_field_offset(tap->field_offset());
5352 const Type* tm = _ary->meet_speculative(tap->_ary);
5353 const TypeAry* tary = tm->isa_ary();
5354 if (tary == nullptr) {
5355 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5356 return tm;
5357 }
5358 PTR ptr = meet_ptr(tap->ptr());
5359 int instance_id = meet_instance_id(tap->instance_id());
5360 const TypePtr* speculative = xmeet_speculative(tap);
5361 int depth = meet_inline_depth(tap->inline_depth());
5362
5363 ciKlass* res_klass = nullptr;
5364 bool res_xk = false;
5365 bool res_flat = false;
5366 bool res_not_flat = false;
5367 bool res_not_null_free = false;
5368 bool res_atomic = false;
5369 const Type* elem = tary->_elem;
5370 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5371 instance_id = InstanceBot;
5372 } else if (this->is_flat() != tap->is_flat()) {
5373 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5374 if (tary->_flat) {
5375 // Result is in a flat representation
5376 off = Offset(is_flat() ? offset() : tap->offset());
5377 field_off = is_flat() ? field_offset() : tap->field_offset();
5378 } else if (below_centerline(ptr)) {
5379 // Result is in a non-flat representation
5380 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5381 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5382 } else if (flat_offset() == tap->flat_offset()) {
5383 off = Offset(!is_flat() ? offset() : tap->offset());
5384 field_off = !is_flat() ? field_offset() : tap->field_offset();
5385 }
5386 }
5387
5388 ciObject* o = nullptr; // Assume not constant when done
5389 ciObject* this_oop = const_oop();
5390 ciObject* tap_oop = tap->const_oop();
5391 if (ptr == Constant) {
5392 if (this_oop != nullptr && tap_oop != nullptr &&
5393 this_oop->equals(tap_oop)) {
5394 o = tap_oop;
5395 } else if (above_centerline(_ptr)) {
5396 o = tap_oop;
5397 } else if (above_centerline(tap->_ptr)) {
5398 o = this_oop;
5399 } else {
5400 ptr = NotNull;
5401 }
5402 }
5403 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);
5404 }
5405
5406 // All arrays inherit from Object class
5407 case InstPtr: {
5408 const TypeInstPtr *tp = t->is_instptr();
5409 Offset offset = meet_offset(tp->offset());
5410 PTR ptr = meet_ptr(tp->ptr());
5411 int instance_id = meet_instance_id(tp->instance_id());
5412 const TypePtr* speculative = xmeet_speculative(tp);
5413 int depth = meet_inline_depth(tp->inline_depth());
5414 const TypeInterfaces* interfaces = meet_interfaces(tp);
5415 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5416 const TypeInterfaces* this_interfaces = _interfaces;
5417
5418 switch (ptr) {
5419 case TopPTR:
5420 case AnyNull: // Fall 'down' to dual of object klass
5421 // For instances when a subclass meets a superclass we fall
5422 // below the centerline when the superclass is exact. We need to
5423 // do the same here.
5424 //
5425 // Flat in array:
5426 // We do
5427 // dual(TypeAryPtr) MEET dual(TypeInstPtr)
5428 // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5429 // instances or arrays).
5430 // If TypeInstPtr is an Object and either
5431 // - exact
5432 // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5433 // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5434 // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5435 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5436 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5437 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5438 } else {
5439 // cannot subclass, so the meet has to fall badly below the centerline
5440 ptr = NotNull;
5441 instance_id = InstanceBot;
5442 interfaces = this_interfaces->intersection_with(tp_interfaces);
5443 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5444 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5445 }
5446 case Constant:
5447 case NotNull:
5448 case BotPTR: { // Fall down to object klass
5449 // LCA is object_klass, but if we subclass from the top we can do better
5450 if (above_centerline(tp->ptr())) {
5451 // If 'tp' is above the centerline and it is Object class
5452 // then we can subclass in the Java class hierarchy.
5453 // For instances when a subclass meets a superclass we fall
5454 // below the centerline when the superclass is exact. We need
5455 // to do the same here.
5456
5457 // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5458 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5459 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5460 // that is, my array type is a subtype of 'tp' klass
5461 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5462 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5463 }
5464 }
5465 // The other case cannot happen, since t cannot be a subtype of an array.
5466 // The meet falls down to Object class below centerline.
5467 if (ptr == Constant) {
5468 ptr = NotNull;
5469 }
5470 if (instance_id > 0) {
5471 instance_id = InstanceBot;
5472 }
5473
5474 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5475 interfaces = this_interfaces->intersection_with(tp_interfaces);
5476 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5477 flat_in_array, instance_id, speculative, depth);
5478 }
5479 default: typerr(t);
5480 }
5481 }
5482 }
5483 return this; // Lint noise
5484 }
5485
5486
5487 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5488 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5489 int dummy;
5490 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5491 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5492 ciKlass* this_klass = this_ary->klass();
5493 ciKlass* other_klass = other_ary->klass();
5494 bool this_xk = this_ary->klass_is_exact();
5495 bool other_xk = other_ary->klass_is_exact();
5496 PTR this_ptr = this_ary->ptr();
5497 PTR other_ptr = other_ary->ptr();
5498 bool this_flat = this_ary->is_flat();
5499 bool this_not_flat = this_ary->is_not_flat();
5500 bool other_flat = other_ary->is_flat();
5501 bool other_not_flat = other_ary->is_not_flat();
5502 bool this_not_null_free = this_ary->is_not_null_free();
5503 bool other_not_null_free = other_ary->is_not_null_free();
5504 bool this_atomic = this_ary->is_atomic();
5505 bool other_atomic = other_ary->is_atomic();
5506 const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5507 res_klass = nullptr;
5508 MeetResult result = SUBTYPE;
5509 res_flat = this_flat && other_flat;
5510 bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5511 res_not_flat = this_not_flat && other_not_flat;
5512 res_not_null_free = this_not_null_free && other_not_null_free;
5513 res_atomic = this_atomic && other_atomic;
5514
5515 if (elem->isa_int()) {
5516 // Integral array element types have irrelevant lattice relations.
5517 // It is the klass that determines array layout, not the element type.
5518 if (this_top_or_bottom) {
5519 res_klass = other_klass;
5520 } else if (other_top_or_bottom || other_klass == this_klass) {
5521 res_klass = this_klass;
5522 } else {
5523 // Something like byte[int+] meets char[int+].
5524 // This must fall to bottom, not (int[-128..65535])[int+].
5525 // instance_id = InstanceBot;
5526 elem = Type::BOTTOM;
5527 result = NOT_SUBTYPE;
5528 if (above_centerline(ptr) || ptr == Constant) {
5529 ptr = NotNull;
5530 res_xk = false;
5531 return NOT_SUBTYPE;
5532 }
5533 }
5534 } else {// Non integral arrays.
5535 // Must fall to bottom if exact klasses in upper lattice
5536 // are not equal or super klass is exact.
5537 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5538 // meet with top[] and bottom[] are processed further down:
5539 !this_top_or_bottom && !other_top_or_bottom &&
5540 // both are exact and not equal:
5542 // 'tap' is exact and super or unrelated:
5543 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5544 // 'this' is exact and super or unrelated:
5545 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5546 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5547 elem = Type::BOTTOM;
5548 }
5549 ptr = NotNull;
5550 res_xk = false;
5551 return NOT_SUBTYPE;
5552 }
5553 }
5554
5555 res_xk = false;
5556 switch (other_ptr) {
5557 case AnyNull:
5558 case TopPTR:
5559 // Compute new klass on demand, do not use tap->_klass
5560 if (below_centerline(this_ptr)) {
5561 res_xk = this_xk;
5562 if (this_ary->is_flat()) {
5563 elem = this_ary->elem();
5564 }
5565 } else {
5566 res_xk = (other_xk || this_xk);
5567 }
5568 break;
5569 case Constant: {
5570 if (this_ptr == Constant && same_nullness) {
5571 // Only exact if same nullness since:
5572 // null-free [LMyValue <: nullable [LMyValue.
5573 res_xk = true;
5574 } else if (above_centerline(this_ptr)) {
5575 res_xk = true;
5576 } else {
5577 // Only precise for identical arrays
5578 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5579 // Even though MyValue is final, [LMyValue is only exact if the array
5580 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5581 if (res_xk && !res_null_free && !res_not_null_free) {
5582 ptr = NotNull;
5583 res_xk = false;
5584 }
5585 }
5586 break;
5587 }
5588 case NotNull:
5589 case BotPTR:
5590 // Compute new klass on demand, do not use tap->_klass
5591 if (above_centerline(this_ptr)) {
5592 res_xk = other_xk;
5593 if (other_ary->is_flat()) {
5594 elem = other_ary->elem();
5595 }
5596 } else {
5597 res_xk = (other_xk && this_xk) &&
5598 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5599 // Even though MyValue is final, [LMyValue is only exact if the array
5600 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5601 if (res_xk && !res_null_free && !res_not_null_free) {
5602 ptr = NotNull;
5603 res_xk = false;
5604 }
5605 }
5606 break;
5607 default: {
5608 ShouldNotReachHere();
5609 return result;
5610 }
5611 }
5612 return result;
5613 }
5614
5615
5616 //------------------------------xdual------------------------------------------
5617 // Dual: compute field-by-field dual
5618 const Type *TypeAryPtr::xdual() const {
5619 bool xk = _klass_is_exact;
5620 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());
5621 }
5622
5623 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5624 return _field_offset.meet(offset);
5625 }
5626
5627 //------------------------------dual_offset------------------------------------
5628 Type::Offset TypeAryPtr::dual_field_offset() const {
5629 return _field_offset.dual();
5630 }
5631
5632 //------------------------------dump2------------------------------------------
5633 #ifndef PRODUCT
5634 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5635 st->print("aryptr:");
5636 _ary->dump2(d, depth, st);
5637 _interfaces->dump(st);
5638
5639 if (_ptr == Constant) {
5640 const_oop()->print(st);
5641 }
5642
5643 st->print(":%s", ptr_msg[_ptr]);
5644 if (_klass_is_exact) {
5645 st->print(":exact");
5646 }
5647
5648 if (is_flat()) {
5649 st->print(":flat");
5650 st->print("(");
5651 _field_offset.dump2(st);
5652 st->print(")");
5653 } else if (is_not_flat()) {
5654 st->print(":not_flat");
5655 }
5656 if (is_null_free()) {
5657 st->print(":null free");
5658 }
5659 if (is_atomic()) {
5660 st->print(":atomic");
5661 }
5662 if (Verbose) {
5663 if (is_not_flat()) {
5664 st->print(":not flat");
5665 }
5666 if (is_not_null_free()) {
5667 st->print(":nullable");
5668 }
5669 }
5670 if (offset() != 0) {
5671 BasicType basic_elem_type = elem()->basic_type();
5672 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5673 if( _offset == Offset::top ) st->print("+undefined");
5674 else if( _offset == Offset::bottom ) st->print("+any");
5675 else if( offset() < header_size ) st->print("+%d", offset());
5676 else {
5677 if (basic_elem_type == T_ILLEGAL) {
5678 st->print("+any");
5679 } else {
5680 int elem_size = type2aelembytes(basic_elem_type);
5681 st->print("[%d]", (offset() - header_size)/elem_size);
5682 }
5683 }
5684 }
5685
5686 dump_instance_id(st);
5687 dump_inline_depth(st);
5688 dump_speculative(st);
5689 }
5690 #endif
5691
5692 bool TypeAryPtr::empty(void) const {
5693 if (_ary->empty()) return true;
5694 // FIXME: Does this belong here? Or in the meet code itself?
5695 if (is_flat() && is_not_flat()) {
5696 return true;
5697 }
5698 return TypeOopPtr::empty();
5699 }
5700
5701 //------------------------------add_offset-------------------------------------
5702 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5703 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);
5704 }
5705
5706 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5707 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);
5708 }
5709
5710 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5711 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5712 }
5713
5714 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5715 if (_speculative == nullptr) {
5716 return this;
5717 }
5718 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5719 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);
5720 }
5721
5722 const Type* TypeAryPtr::cleanup_speculative() const {
5723 if (speculative() == nullptr) {
5724 return this;
5725 }
5726 // Keep speculative part if it contains information about flat-/nullability
5727 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5728 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5729 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5730 return this;
5731 }
5732 return TypeOopPtr::cleanup_speculative();
5733 }
5734
5735 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5736 if (!UseInlineDepthForSpeculativeTypes) {
5737 return this;
5738 }
5739 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5740 }
5741
5742 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5743 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);
5744 }
5745
5746 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5747 int adj = 0;
5748 if (is_flat() && klass_is_exact() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5749 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5750 adj = _offset.get();
5751 offset += _offset.get();
5752 }
5753 uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5754 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5755 offset += _field_offset.get();
5756 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5757 offset += header;
5758 }
5759 }
5760 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5761 // Try to get the field of the inline type array element we are pointing to
5762 ciInlineKlass* vk = elem()->inline_klass();
5763 int shift = flat_log_elem_size();
5764 int mask = (1 << shift) - 1;
5765 intptr_t field_offset = ((offset - header) & mask);
5766 ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5767 if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5768 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5769 }
5770 }
5771 }
5772 return add_offset(offset - adj);
5773 }
5774
5775 // Return offset incremented by field_offset for flat inline type arrays
5776 int TypeAryPtr::flat_offset() const {
5777 int offset = _offset.get();
5778 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5779 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5780 offset += _field_offset.get();
5781 }
5782 return offset;
5783 }
5784
5785 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5786 assert(is_known_instance(), "should be known");
5787 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5788 }
5789
5790 //=============================================================================
5791
5792
5793 //------------------------------hash-------------------------------------------
5794 // Type-specific hashing function.
5795 uint TypeNarrowPtr::hash(void) const {
5796 return _ptrtype->hash() + 7;
5797 }
5798
5799 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5800 return _ptrtype->singleton();
5801 }
5802
5803 bool TypeNarrowPtr::empty(void) const {
5804 return _ptrtype->empty();
5805 }
5806
5807 intptr_t TypeNarrowPtr::get_con() const {
5808 return _ptrtype->get_con();
5809 }
5810
5811 bool TypeNarrowPtr::eq( const Type *t ) const {
5812 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5866 case HalfFloatTop:
5867 case HalfFloatCon:
5868 case HalfFloatBot:
5869 case FloatTop:
5870 case FloatCon:
5871 case FloatBot:
5872 case DoubleTop:
5873 case DoubleCon:
5874 case DoubleBot:
5875 case AnyPtr:
5876 case RawPtr:
5877 case OopPtr:
5878 case InstPtr:
5879 case AryPtr:
5880 case MetadataPtr:
5881 case KlassPtr:
5882 case InstKlassPtr:
5883 case AryKlassPtr:
5884 case NarrowOop:
5885 case NarrowKlass:
5886 case Bottom: // Ye Olde Default
5887 return Type::BOTTOM;
5888 case Top:
5889 return this;
5890
5891 default: // All else is a mistake
5892 typerr(t);
5893
5894 } // End of switch
5895
5896 return this;
5897 }
5898
5899 #ifndef PRODUCT
5900 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5901 _ptrtype->dump2(d, depth, st);
5902 }
5903 #endif
5904
5905 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5949 return (one == two) && TypePtr::eq(t);
5950 } else {
5951 return one->equals(two) && TypePtr::eq(t);
5952 }
5953 }
5954
5955 //------------------------------hash-------------------------------------------
5956 // Type-specific hashing function.
5957 uint TypeMetadataPtr::hash(void) const {
5958 return
5959 (metadata() ? metadata()->hash() : 0) +
5960 TypePtr::hash();
5961 }
5962
5963 //------------------------------singleton--------------------------------------
5964 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5965 // constants
5966 bool TypeMetadataPtr::singleton(void) const {
5967 // detune optimizer to not generate constant metadata + constant offset as a constant!
5968 // TopPTR, Null, AnyNull, Constant are all singletons
5969 return (offset() == 0) && !below_centerline(_ptr);
5970 }
5971
5972 //------------------------------add_offset-------------------------------------
5973 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5974 return make( _ptr, _metadata, xadd_offset(offset));
5975 }
5976
5977 //-----------------------------filter------------------------------------------
5978 // Do not allow interface-vs.-noninterface joins to collapse to top.
5979 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5980 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5981 if (ft == nullptr || ft->empty())
5982 return Type::TOP; // Canonical empty value
5983 return ft;
5984 }
5985
5986 //------------------------------get_con----------------------------------------
5987 intptr_t TypeMetadataPtr::get_con() const {
5988 assert( _ptr == Null || _ptr == Constant, "" );
5989 assert(offset() >= 0, "");
5990
5991 if (offset() != 0) {
5992 // After being ported to the compiler interface, the compiler no longer
5993 // directly manipulates the addresses of oops. Rather, it only has a pointer
5994 // to a handle at compile time. This handle is embedded in the generated
5995 // code and dereferenced at the time the nmethod is made. Until that time,
5996 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5997 // have access to the addresses!). This does not seem to currently happen,
5998 // but this assertion here is to help prevent its occurrence.
5999 tty->print_cr("Found oop constant with non-zero offset");
6000 ShouldNotReachHere();
6001 }
6002
6003 return (intptr_t)metadata()->constant_encoding();
6004 }
6005
6006 //------------------------------cast_to_ptr_type-------------------------------
6007 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6008 if( ptr == _ptr ) return this;
6009 return make(ptr, metadata(), _offset);
6010 }
6011
6025 case HalfFloatBot:
6026 case FloatTop:
6027 case FloatCon:
6028 case FloatBot:
6029 case DoubleTop:
6030 case DoubleCon:
6031 case DoubleBot:
6032 case NarrowOop:
6033 case NarrowKlass:
6034 case Bottom: // Ye Olde Default
6035 return Type::BOTTOM;
6036 case Top:
6037 return this;
6038
6039 default: // All else is a mistake
6040 typerr(t);
6041
6042 case AnyPtr: {
6043 // Found an AnyPtr type vs self-OopPtr type
6044 const TypePtr *tp = t->is_ptr();
6045 Offset offset = meet_offset(tp->offset());
6046 PTR ptr = meet_ptr(tp->ptr());
6047 switch (tp->ptr()) {
6048 case Null:
6049 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6050 // else fall through:
6051 case TopPTR:
6052 case AnyNull: {
6053 return make(ptr, _metadata, offset);
6054 }
6055 case BotPTR:
6056 case NotNull:
6057 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6058 default: typerr(t);
6059 }
6060 }
6061
6062 case RawPtr:
6063 case KlassPtr:
6064 case InstKlassPtr:
6065 case AryKlassPtr:
6066 case OopPtr:
6067 case InstPtr:
6068 case AryPtr:
6069 return TypePtr::BOTTOM; // Oop meet raw is not well defined
6070
6071 case MetadataPtr: {
6072 const TypeMetadataPtr *tp = t->is_metadataptr();
6073 Offset offset = meet_offset(tp->offset());
6074 PTR tptr = tp->ptr();
6075 PTR ptr = meet_ptr(tptr);
6076 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6077 if (tptr == TopPTR || _ptr == TopPTR ||
6078 metadata()->equals(tp->metadata())) {
6079 return make(ptr, md, offset);
6080 }
6081 // metadata is different
6082 if( ptr == Constant ) { // Cannot be equal constants, so...
6083 if( tptr == Constant && _ptr != Constant) return t;
6084 if( _ptr == Constant && tptr != Constant) return this;
6085 ptr = NotNull; // Fall down in lattice
6086 }
6087 return make(ptr, nullptr, offset);
6088 break;
6089 }
6090 } // End of switch
6091 return this; // Return the double constant
6092 }
6093
6097 const Type *TypeMetadataPtr::xdual() const {
6098 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6099 }
6100
6101 //------------------------------dump2------------------------------------------
6102 #ifndef PRODUCT
6103 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6104 st->print("metadataptr:%s", ptr_msg[_ptr]);
6105 if (metadata() != nullptr) {
6106 st->print(":" INTPTR_FORMAT, p2i(metadata()));
6107 }
6108 dump_offset(st);
6109 }
6110 #endif
6111
6112
6113 //=============================================================================
6114 // Convenience common pre-built type.
6115 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6116
6117 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6118 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6119 }
6120
6121 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6122 return make(Constant, m, Offset(0));
6123 }
6124 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6125 return make(Constant, m, Offset(0));
6126 }
6127
6128 //------------------------------make-------------------------------------------
6129 // Create a meta data constant
6130 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6131 assert(m == nullptr || !m->is_klass(), "wrong type");
6132 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6133 }
6134
6135
6136 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6137 const Type* elem = _ary->_elem;
6138 bool xk = klass_is_exact();
6139 bool is_refined = false;
6140 if (elem->make_oopptr() != nullptr) {
6141 is_refined = true;
6142 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6143 if (elem->isa_aryklassptr()) {
6144 const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6145 if (elem_klass->is_refined_type()) {
6146 elem = elem_klass->cast_to_non_refined();
6147 }
6148 } else {
6149 const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6150 if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6151 !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6152 xk = true;
6153 }
6154 }
6155 }
6156 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);
6157 }
6158
6159 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6160 if (klass->is_instance_klass()) {
6161 return TypeInstKlassPtr::make(klass, interface_handling);
6162 }
6163 return TypeAryKlassPtr::make(klass, interface_handling);
6164 }
6165
6166 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
6167 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6168 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6169 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6170 }
6171
6172 // Is there a single ciKlass* that can represent that type?
6173 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6174 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6175 if (_interfaces->empty()) {
6176 return _klass;
6177 }
6178 if (_klass != ciEnv::current()->Object_klass()) {
6179 if (_interfaces->eq(_klass->as_instance_klass())) {
6180 return _klass;
6181 }
6182 return nullptr;
6183 }
6184 return _interfaces->exact_klass();
6185 }
6186
6187 //------------------------------eq---------------------------------------------
6188 // Structural equality check for Type representations
6189 bool TypeKlassPtr::eq(const Type *t) const {
6190 const TypeKlassPtr *p = t->is_klassptr();
6191 return
6192 _interfaces->eq(p->_interfaces) &&
6193 TypePtr::eq(p);
6194 }
6195
6196 //------------------------------hash-------------------------------------------
6197 // Type-specific hashing function.
6198 uint TypeKlassPtr::hash(void) const {
6199 return TypePtr::hash() + _interfaces->hash();
6200 }
6201
6202 //------------------------------singleton--------------------------------------
6203 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6204 // constants
6205 bool TypeKlassPtr::singleton(void) const {
6206 // detune optimizer to not generate constant klass + constant offset as a constant!
6207 // TopPTR, Null, AnyNull, Constant are all singletons
6208 return (offset() == 0) && !below_centerline(_ptr);
6209 }
6210
6211 // Do not allow interface-vs.-noninterface joins to collapse to top.
6212 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6213 // logic here mirrors the one from TypeOopPtr::filter. See comments
6214 // there.
6215 const Type* ft = join_helper(kills, include_speculative);
6216
6217 if (ft->empty()) {
6218 return Type::TOP; // Canonical empty value
6219 }
6220
6221 return ft;
6222 }
6223
6224 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6225 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6226 return _interfaces->union_with(other->_interfaces);
6227 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6228 return other->_interfaces;
6229 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6230 return _interfaces;
6231 }
6232 return _interfaces->intersection_with(other->_interfaces);
6233 }
6234
6235 //------------------------------get_con----------------------------------------
6236 intptr_t TypeKlassPtr::get_con() const {
6237 assert( _ptr == Null || _ptr == Constant, "" );
6238 assert( offset() >= 0, "" );
6239
6240 if (offset() != 0) {
6241 // After being ported to the compiler interface, the compiler no longer
6242 // directly manipulates the addresses of oops. Rather, it only has a pointer
6243 // to a handle at compile time. This handle is embedded in the generated
6244 // code and dereferenced at the time the nmethod is made. Until that time,
6245 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6246 // have access to the addresses!). This does not seem to currently happen,
6247 // but this assertion here is to help prevent its occurrence.
6248 tty->print_cr("Found oop constant with non-zero offset");
6249 ShouldNotReachHere();
6250 }
6251
6252 ciKlass* k = exact_klass();
6253
6254 return (intptr_t)k->constant_encoding();
6255 }
6256
6257 //=============================================================================
6258 // Convenience common pre-built types.
6259
6260 // Not-null object klass or below
6261 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6262 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6263
6264 bool TypeInstKlassPtr::eq(const Type *t) const {
6265 const TypeInstKlassPtr* p = t->is_instklassptr();
6266 return
6267 klass()->equals(p->klass()) &&
6268 _flat_in_array == p->_flat_in_array &&
6269 TypeKlassPtr::eq(p);
6270 }
6271
6272 uint TypeInstKlassPtr::hash() const {
6273 return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6274 }
6275
6276 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6277 if (flat_in_array == Uninitialized) {
6278 flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6279 }
6280 TypeInstKlassPtr *r =
6281 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6282
6283 return r;
6284 }
6285
6286 bool TypeInstKlassPtr::empty() const {
6287 if (_flat_in_array == TopFlat) {
6288 return true;
6289 }
6290 return TypeKlassPtr::empty();
6291 }
6292
6293 //------------------------------add_offset-------------------------------------
6294 // Access internals of klass object
6295 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6296 return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6297 }
6298
6299 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6300 return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6301 }
6302
6303 //------------------------------cast_to_ptr_type-------------------------------
6304 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6305 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6306 if( ptr == _ptr ) return this;
6307 return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6308 }
6309
6310
6311 bool TypeInstKlassPtr::must_be_exact() const {
6312 if (!_klass->is_loaded()) return false;
6313 ciInstanceKlass* ik = _klass->as_instance_klass();
6314 if (ik->is_final()) return true; // cannot clear xk
6315 return false;
6316 }
6317
6318 //-----------------------------cast_to_exactness-------------------------------
6319 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6320 if (klass_is_exact == (_ptr == Constant)) return this;
6321 if (must_be_exact()) return this;
6322 ciKlass* k = klass();
6323 FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6324 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6325 }
6326
6327
6328 //-----------------------------as_instance_type--------------------------------
6329 // Corresponding type for an instance of the given class.
6330 // It will be NotNull, and exact if and only if the klass type is exact.
6331 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6332 ciKlass* k = klass();
6333 bool xk = klass_is_exact();
6334 Compile* C = Compile::current();
6335 Dependencies* deps = C->dependencies();
6336 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6337 // Element is an instance
6338 bool klass_is_exact = false;
6339 const TypeInterfaces* interfaces = _interfaces;
6340 ciInstanceKlass* ik = k->as_instance_klass();
6341 if (k->is_loaded()) {
6342 // Try to set klass_is_exact.
6343 klass_is_exact = ik->is_final();
6344 if (!klass_is_exact && klass_change
6345 && deps != nullptr && UseUniqueSubclasses) {
6346 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6347 if (sub != nullptr) {
6348 if (_interfaces->eq(sub)) {
6349 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6350 k = ik = sub;
6351 xk = sub->is_final();
6352 }
6353 }
6354 }
6355 }
6356
6357 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6358 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6359 }
6360
6361 //------------------------------xmeet------------------------------------------
6362 // Compute the MEET of two types, return a new Type object.
6363 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6364 // Perform a fast test for common case; meeting the same types together.
6365 if( this == t ) return this; // Meeting same type-rep?
6366
6367 // Current "this->_base" is Pointer
6368 switch (t->base()) { // switch on original type
6369
6370 case Int: // Mixing ints & oops happens when javac
6371 case Long: // reuses local variables
6372 case HalfFloatTop:
6373 case HalfFloatCon:
6374 case HalfFloatBot:
6375 case FloatTop:
6376 case FloatCon:
6377 case FloatBot:
6378 case DoubleTop:
6379 case DoubleCon:
6380 case DoubleBot:
6381 case NarrowOop:
6382 case NarrowKlass:
6383 case Bottom: // Ye Olde Default
6384 return Type::BOTTOM;
6385 case Top:
6386 return this;
6387
6388 default: // All else is a mistake
6389 typerr(t);
6390
6391 case AnyPtr: { // Meeting to AnyPtrs
6392 // Found an AnyPtr type vs self-KlassPtr type
6393 const TypePtr *tp = t->is_ptr();
6394 Offset offset = meet_offset(tp->offset());
6395 PTR ptr = meet_ptr(tp->ptr());
6396 switch (tp->ptr()) {
6397 case TopPTR:
6398 return this;
6399 case Null:
6400 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6401 case AnyNull:
6402 return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6403 case BotPTR:
6404 case NotNull:
6405 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6406 default: typerr(t);
6407 }
6408 }
6409
6410 case RawPtr:
6411 case MetadataPtr:
6412 case OopPtr:
6413 case AryPtr: // Meet with AryPtr
6414 case InstPtr: // Meet with InstPtr
6415 return TypePtr::BOTTOM;
6416
6417 //
6418 // A-top }
6419 // / | \ } Tops
6420 // B-top A-any C-top }
6421 // | / | \ | } Any-nulls
6422 // B-any | C-any }
6423 // | | |
6424 // B-con A-con C-con } constants; not comparable across classes
6425 // | | |
6426 // B-not | C-not }
6427 // | \ | / | } not-nulls
6428 // B-bot A-not C-bot }
6429 // \ | / } Bottoms
6430 // A-bot }
6431 //
6432
6433 case InstKlassPtr: { // Meet two KlassPtr types
6434 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6435 Offset off = meet_offset(tkls->offset());
6436 PTR ptr = meet_ptr(tkls->ptr());
6437 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6438
6439 ciKlass* res_klass = nullptr;
6440 bool res_xk = false;
6441 const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6442 switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6443 case UNLOADED:
6444 ShouldNotReachHere();
6445 case SUBTYPE:
6446 case NOT_SUBTYPE:
6447 case LCA:
6448 case QUICK: {
6449 assert(res_xk == (ptr == Constant), "");
6450 const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6451 return res;
6452 }
6453 default:
6454 ShouldNotReachHere();
6455 }
6456 } // End of case KlassPtr
6457 case AryKlassPtr: { // All arrays inherit from Object class
6458 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6459 Offset offset = meet_offset(tp->offset());
6460 PTR ptr = meet_ptr(tp->ptr());
6461 const TypeInterfaces* interfaces = meet_interfaces(tp);
6462 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6463 const TypeInterfaces* this_interfaces = _interfaces;
6464
6465 switch (ptr) {
6466 case TopPTR:
6467 case AnyNull: // Fall 'down' to dual of object klass
6468 // For instances when a subclass meets a superclass we fall
6469 // below the centerline when the superclass is exact. We need to
6470 // do the same here.
6471 //
6472 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6473 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6474 !klass_is_exact() && !is_not_flat_in_array()) {
6475 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());
6476 } else {
6477 // cannot subclass, so the meet has to fall badly below the centerline
6478 ptr = NotNull;
6479 interfaces = _interfaces->intersection_with(tp->_interfaces);
6480 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6481 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6482 }
6483 case Constant:
6484 case NotNull:
6485 case BotPTR: { // Fall down to object klass
6486 // LCA is object_klass, but if we subclass from the top we can do better
6487 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6488 // If 'this' (InstPtr) is above the centerline and it is Object class
6489 // then we can subclass in the Java class hierarchy.
6490 // For instances when a subclass meets a superclass we fall
6491 // below the centerline when the superclass is exact. We need
6492 // to do the same here.
6493 //
6494 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6495 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6496 !klass_is_exact() && !is_not_flat_in_array()) {
6497 // that is, tp's array type is a subtype of my klass
6498 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_flat(), tp->is_null_free(), tp->is_atomic(), tp->is_refined_type());
6499 }
6500 }
6501 // The other case cannot happen, since I cannot be a subtype of an array.
6502 // The meet falls down to Object class below centerline.
6503 if( ptr == Constant )
6504 ptr = NotNull;
6505 interfaces = this_interfaces->intersection_with(tp_interfaces);
6506 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6507 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6508 }
6509 default: typerr(t);
6510 }
6511 }
6512
6513 } // End of switch
6514 return this; // Return the double constant
6515 }
6516
6517 //------------------------------xdual------------------------------------------
6518 // Dual: compute field-by-field dual
6519 const Type* TypeInstKlassPtr::xdual() const {
6520 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6521 }
6522
6523 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) {
6524 static_assert(std::is_base_of<T2, T1>::value, "");
6525 if (!this_one->is_loaded() || !other->is_loaded()) {
6526 return false;
6527 }
6528 if (!this_one->is_instance_type(other)) {
6529 return false;
6530 }
6531
6532 if (!other_exact) {
6533 return false;
6534 }
6535
6536 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6537 return true;
6538 }
6539
6540 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6594
6595 if (this_exact) {
6596 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6597 }
6598
6599 return true;
6600 }
6601
6602 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6603 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6604 }
6605
6606 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6607 if (!UseUniqueSubclasses) {
6608 return this;
6609 }
6610 ciKlass* k = klass();
6611 Compile* C = Compile::current();
6612 Dependencies* deps = C->dependencies();
6613 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6614 if (k->is_loaded()) {
6615 ciInstanceKlass* ik = k->as_instance_klass();
6616 if (deps != nullptr) {
6617 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6618 if (sub != nullptr) {
6619 bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6620 const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6621 if (improved->_interfaces->contains(_interfaces)) {
6622 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6623 return improved;
6624 }
6625 }
6626 }
6627 }
6628 return this;
6629 }
6630
6631 bool TypeInstKlassPtr::can_be_inline_array() const {
6632 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6633 }
6634
6635 #ifndef PRODUCT
6636 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6637 st->print("instklassptr:");
6638 klass()->print_name_on(st);
6639 _interfaces->dump(st);
6640 st->print(":%s", ptr_msg[_ptr]);
6641 dump_offset(st);
6642 dump_flat_in_array(_flat_in_array, st);
6643 }
6644 #endif // PRODUCT
6645
6646 bool TypeAryKlassPtr::can_be_inline_array() const {
6647 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6648 }
6649
6650 bool TypeInstPtr::can_be_inline_array() const {
6651 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6652 }
6653
6654 bool TypeAryPtr::can_be_inline_array() const {
6655 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6656 }
6657
6658 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) {
6659 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6660 }
6661
6662 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) {
6663 const Type* etype;
6664 if (k->is_obj_array_klass()) {
6665 // Element is an object array. Recursively call ourself.
6666 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6667 etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6668 k = nullptr;
6669 } else if (k->is_type_array_klass()) {
6670 // Element is an typeArray
6671 etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6672 } else {
6673 ShouldNotReachHere();
6674 }
6675
6676 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6677 }
6678
6679 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6680 ciArrayKlass* k = klass->as_array_klass();
6681 if (k->is_refined()) {
6682 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6683 k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6684 } else {
6685 // Use the default combination to canonicalize all non-refined klass pointers
6686 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6687 }
6688 }
6689
6690 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6691 assert(is_refined_type(), "must be a refined type");
6692 PTR ptr = _ptr;
6693 // There can be multiple refined array types corresponding to a single unrefined type
6694 if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6695 ptr = Constant;
6696 }
6697 return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6698 }
6699
6700 // Get the (non-)refined array klass ptr
6701 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6702 if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6703 return this;
6704 }
6705 ciArrayKlass* k = exact_klass()->as_array_klass();
6706 k = ciObjArrayKlass::make(k->element_klass(), refined);
6707 return make(k, trust_interfaces);
6708 }
6709
6710 //------------------------------eq---------------------------------------------
6711 // Structural equality check for Type representations
6712 bool TypeAryKlassPtr::eq(const Type *t) const {
6713 const TypeAryKlassPtr *p = t->is_aryklassptr();
6714 return
6715 _elem == p->_elem && // Check array
6716 _flat == p->_flat &&
6717 _not_flat == p->_not_flat &&
6718 _null_free == p->_null_free &&
6719 _not_null_free == p->_not_null_free &&
6720 _atomic == p->_atomic &&
6721 _refined_type == p->_refined_type &&
6722 TypeKlassPtr::eq(p); // Check sub-parts
6723 }
6724
6725 //------------------------------hash-------------------------------------------
6726 // Type-specific hashing function.
6727 uint TypeAryKlassPtr::hash(void) const {
6728 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6729 (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6730 }
6731
6732 //----------------------compute_klass------------------------------------------
6733 // Compute the defining klass for this class
6734 ciKlass* TypeAryPtr::compute_klass() const {
6735 // Compute _klass based on element type.
6736 ciKlass* k_ary = nullptr;
6737 const TypeInstPtr *tinst;
6738 const TypeAryPtr *tary;
6739 const Type* el = elem();
6740 if (el->isa_narrowoop()) {
6741 el = el->make_ptr();
6742 }
6743
6744 // Get element klass
6745 if ((tinst = el->isa_instptr()) != nullptr) {
6746 // Leave k_ary at nullptr.
6747 } else if ((tary = el->isa_aryptr()) != nullptr) {
6748 // Leave k_ary at nullptr.
6749 } else if ((el->base() == Type::Top) ||
6750 (el->base() == Type::Bottom)) {
6751 // element type of Bottom occurs from meet of basic type
6752 // and object; Top occurs when doing join on Bottom.
6753 // Leave k_ary at null.
6754 } else {
6755 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6756 // Compute array klass directly from basic type
6757 k_ary = ciTypeArrayKlass::make(el->basic_type());
6758 }
6759 return k_ary;
6760 }
6761
6762 //------------------------------klass------------------------------------------
6763 // Return the defining klass for this class
6764 ciKlass* TypeAryPtr::klass() const {
6765 if( _klass ) return _klass; // Return cached value, if possible
6766
6767 // Oops, need to compute _klass and cache it
6768 ciKlass* k_ary = compute_klass();
6776 // type TypeAryPtr::OOPS. This Type is shared between all
6777 // active compilations. However, the ciKlass which represents
6778 // this Type is *not* shared between compilations, so caching
6779 // this value would result in fetching a dangling pointer.
6780 //
6781 // Recomputing the underlying ciKlass for each request is
6782 // a bit less efficient than caching, but calls to
6783 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6784 ((TypeAryPtr*)this)->_klass = k_ary;
6785 }
6786 return k_ary;
6787 }
6788
6789 // Is there a single ciKlass* that can represent that type?
6790 ciKlass* TypeAryPtr::exact_klass_helper() const {
6791 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6792 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6793 if (k == nullptr) {
6794 return nullptr;
6795 }
6796 if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6797 // We have no mechanism to create an array of refined arrays
6798 k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6799 }
6800 if (klass_is_exact()) {
6801 return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6802 } else {
6803 // We may reach here if called recursively, must be an unrefined type then
6804 return ciObjArrayKlass::make(k, false);
6805 }
6806 }
6807
6808 return klass();
6809 }
6810
6811 const Type* TypeAryPtr::base_element_type(int& dims) const {
6812 const Type* elem = this->elem();
6813 dims = 1;
6814 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6815 elem = elem->make_ptr()->is_aryptr()->elem();
6816 dims++;
6817 }
6818 return elem;
6819 }
6820
6821 //------------------------------add_offset-------------------------------------
6822 // Access internals of klass object
6823 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6824 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6825 }
6826
6827 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6828 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6829 }
6830
6831 //------------------------------cast_to_ptr_type-------------------------------
6832 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6833 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6834 if (ptr == _ptr) return this;
6835 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6836 }
6837
6838 bool TypeAryKlassPtr::must_be_exact() const {
6839 assert(klass_is_exact(), "precondition");
6840 if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6841 return false;
6842 }
6843 const TypeKlassPtr* elem = _elem->isa_klassptr();
6844 if (elem == nullptr) {
6845 // primitive arrays
6846 return true;
6847 }
6848
6849 // refined types are final
6850 return _refined_type;
6851 }
6852
6853 //-----------------------------cast_to_exactness-------------------------------
6854 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6855 if (klass_is_exact == this->klass_is_exact()) {
6856 return this;
6857 }
6858 if (!klass_is_exact && must_be_exact()) {
6859 return this;
6860 }
6861 const Type* elem = this->elem();
6862 if (elem->isa_klassptr() && !klass_is_exact) {
6863 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6864 }
6865
6866 if (klass_is_exact) {
6867 // cast_to_exactness(true) really means get the LCA of all values represented by this
6868 // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6869 return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6870 } else {
6871 // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6872 // this value
6873 bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6874 bool not_flat = !UseArrayFlattening || not_inline ||
6875 (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6876 bool not_null_free = not_inline;
6877 bool atomic = not_flat;
6878 return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6879 }
6880 }
6881
6882 //-----------------------------as_instance_type--------------------------------
6883 // Corresponding type for an instance of the given class.
6884 // It will be NotNull, and exact if and only if the klass type is exact.
6885 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6886 ciKlass* k = klass();
6887 bool xk = klass_is_exact();
6888 const Type* el = nullptr;
6889 if (elem()->isa_klassptr()) {
6890 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6891 k = nullptr;
6892 } else {
6893 el = elem();
6894 }
6895 bool null_free = _null_free;
6896 if (null_free && el->isa_ptr()) {
6897 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6898 }
6899 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));
6900 }
6901
6902
6903 //------------------------------xmeet------------------------------------------
6904 // Compute the MEET of two types, return a new Type object.
6905 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6906 // Perform a fast test for common case; meeting the same types together.
6907 if( this == t ) return this; // Meeting same type-rep?
6908
6909 // Current "this->_base" is Pointer
6910 switch (t->base()) { // switch on original type
6911
6912 case Int: // Mixing ints & oops happens when javac
6913 case Long: // reuses local variables
6914 case HalfFloatTop:
6915 case HalfFloatCon:
6916 case HalfFloatBot:
6917 case FloatTop:
6918 case FloatCon:
6919 case FloatBot:
6920 case DoubleTop:
6921 case DoubleCon:
6922 case DoubleBot:
6923 case NarrowOop:
6924 case NarrowKlass:
6925 case Bottom: // Ye Olde Default
6926 return Type::BOTTOM;
6927 case Top:
6928 return this;
6929
6930 default: // All else is a mistake
6931 typerr(t);
6932
6933 case AnyPtr: { // Meeting to AnyPtrs
6934 // Found an AnyPtr type vs self-KlassPtr type
6935 const TypePtr *tp = t->is_ptr();
6936 Offset offset = meet_offset(tp->offset());
6937 PTR ptr = meet_ptr(tp->ptr());
6938 switch (tp->ptr()) {
6939 case TopPTR:
6940 return this;
6941 case Null:
6942 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6943 case AnyNull:
6944 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6945 case BotPTR:
6946 case NotNull:
6947 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6948 default: typerr(t);
6949 }
6950 }
6951
6952 case RawPtr:
6953 case MetadataPtr:
6954 case OopPtr:
6955 case AryPtr: // Meet with AryPtr
6956 case InstPtr: // Meet with InstPtr
6957 return TypePtr::BOTTOM;
6958
6959 //
6960 // A-top }
6961 // / | \ } Tops
6962 // B-top A-any C-top }
6963 // | / | \ | } Any-nulls
6964 // B-any | C-any }
6965 // | | |
6966 // B-con A-con C-con } constants; not comparable across classes
6967 // | | |
6968 // B-not | C-not }
6969 // | \ | / | } not-nulls
6970 // B-bot A-not C-bot }
6971 // \ | / } Bottoms
6972 // A-bot }
6973 //
6974
6975 case AryKlassPtr: { // Meet two KlassPtr types
6976 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6977 Offset off = meet_offset(tap->offset());
6978 const Type* elem = _elem->meet(tap->_elem);
6979 PTR ptr = meet_ptr(tap->ptr());
6980 ciKlass* res_klass = nullptr;
6981 bool res_xk = false;
6982 bool res_flat = false;
6983 bool res_not_flat = false;
6984 bool res_not_null_free = false;
6985 bool res_atomic = false;
6986 MeetResult res = meet_aryptr(ptr, elem, this, tap,
6987 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
6988 assert(res_xk == (ptr == Constant), "");
6989 bool flat = meet_flat(tap->_flat);
6990 bool null_free = meet_null_free(tap->_null_free);
6991 bool atomic = meet_atomic(tap->_atomic);
6992 bool refined_type = _refined_type && tap->_refined_type;
6993 if (res == NOT_SUBTYPE) {
6994 flat = false;
6995 null_free = false;
6996 atomic = false;
6997 refined_type = false;
6998 } else if (res == SUBTYPE) {
6999 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7000 flat = _flat;
7001 null_free = _null_free;
7002 atomic = _atomic;
7003 refined_type = _refined_type;
7004 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7005 flat = tap->_flat;
7006 null_free = tap->_null_free;
7007 atomic = tap->_atomic;
7008 refined_type = tap->_refined_type;
7009 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7010 flat = _flat || tap->_flat;
7011 null_free = _null_free || tap->_null_free;
7012 atomic = _atomic || tap->_atomic;
7013 refined_type = _refined_type || tap->_refined_type;
7014 } else if (res_xk && _refined_type != tap->_refined_type) {
7015 // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
7016 // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
7017 // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
7018 ptr = PTR::NotNull;
7019 }
7020 }
7021 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
7022 } // End of case KlassPtr
7023 case InstKlassPtr: {
7024 const TypeInstKlassPtr *tp = t->is_instklassptr();
7025 Offset offset = meet_offset(tp->offset());
7026 PTR ptr = meet_ptr(tp->ptr());
7027 const TypeInterfaces* interfaces = meet_interfaces(tp);
7028 const TypeInterfaces* tp_interfaces = tp->_interfaces;
7029 const TypeInterfaces* this_interfaces = _interfaces;
7030
7031 switch (ptr) {
7032 case TopPTR:
7033 case AnyNull: // Fall 'down' to dual of object klass
7034 // For instances when a subclass meets a superclass we fall
7035 // below the centerline when the superclass is exact. We need to
7036 // do the same here.
7037 //
7038 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7039 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7040 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7041 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7042 } else {
7043 // cannot subclass, so the meet has to fall badly below the centerline
7044 ptr = NotNull;
7045 interfaces = this_interfaces->intersection_with(tp->_interfaces);
7046 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7047 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7048 }
7049 case Constant:
7050 case NotNull:
7051 case BotPTR: { // Fall down to object klass
7052 // LCA is object_klass, but if we subclass from the top we can do better
7053 if (above_centerline(tp->ptr())) {
7054 // If 'tp' is above the centerline and it is Object class
7055 // then we can subclass in the Java class hierarchy.
7056 // For instances when a subclass meets a superclass we fall
7057 // below the centerline when the superclass is exact. We need
7058 // to do the same here.
7059 //
7060 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7061 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7062 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7063 // that is, my array type is a subtype of 'tp' klass
7064 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7065 }
7066 }
7067 // The other case cannot happen, since t cannot be a subtype of an array.
7068 // The meet falls down to Object class below centerline.
7069 if (ptr == Constant)
7070 ptr = NotNull;
7071 interfaces = this_interfaces->intersection_with(tp_interfaces);
7072 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7073 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, tp->flat_in_array());
7074 }
7075 default: typerr(t);
7076 }
7077 }
7078
7079 } // End of switch
7080 return this; // Return the double constant
7081 }
7082
7083 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) {
7084 static_assert(std::is_base_of<T2, T1>::value, "");
7085
7086 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7087 return true;
7088 }
7089
7090 int dummy;
7091 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7092
7093 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7094 return false;
7095 }
7096
7097 if (this_one->is_instance_type(other)) {
7098 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7099 other_exact;
7100 }
7101
7102 assert(this_one->is_array_type(other), "");
7103 const T1* other_ary = this_one->is_array_type(other);
7104 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7105 if (other_top_or_bottom) {
7106 return false;
7107 }
7108
7109 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7110 const TypePtr* this_elem = this_one->elem()->make_ptr();
7111 if (this_elem != nullptr && other_elem != nullptr) {
7112 if (other->is_null_free() && !this_one->is_null_free()) {
7113 return false; // A nullable array can't be a subtype of a null-free array
7114 }
7115 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7116 }
7117 if (this_elem == nullptr && other_elem == nullptr) {
7118 return this_one->klass()->is_subtype_of(other->klass());
7119 }
7120 return false;
7121 }
7122
7123 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7124 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7125 }
7126
7127 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7128 static_assert(std::is_base_of<T2, T1>::value, "");
7129
7130 int dummy;
7131 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7132
7133 if (!this_one->is_array_type(other) ||
7134 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7187 }
7188
7189 const TypePtr* this_elem = this_one->elem()->make_ptr();
7190 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7191 if (other_elem != nullptr && this_elem != nullptr) {
7192 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7193 }
7194 if (other_elem == nullptr && this_elem == nullptr) {
7195 return this_one->klass()->is_subtype_of(other->klass());
7196 }
7197 return false;
7198 }
7199
7200 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7201 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7202 }
7203
7204 //------------------------------xdual------------------------------------------
7205 // Dual: compute field-by-field dual
7206 const Type *TypeAryKlassPtr::xdual() const {
7207 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);
7208 }
7209
7210 // Is there a single ciKlass* that can represent that type?
7211 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7212 if (elem()->isa_klassptr()) {
7213 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7214 if (k == nullptr) {
7215 return nullptr;
7216 }
7217 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());
7218 k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7219 return k;
7220 }
7221
7222 return klass();
7223 }
7224
7225 ciKlass* TypeAryKlassPtr::klass() const {
7226 if (_klass != nullptr) {
7227 return _klass;
7228 }
7229 ciKlass* k = nullptr;
7230 if (elem()->isa_klassptr()) {
7231 // leave null
7232 } else if ((elem()->base() == Type::Top) ||
7233 (elem()->base() == Type::Bottom)) {
7234 } else {
7235 k = ciTypeArrayKlass::make(elem()->basic_type());
7236 ((TypeAryKlassPtr*)this)->_klass = k;
7237 }
7238 return k;
7239 }
7240
7241 //------------------------------dump2------------------------------------------
7242 // Dump Klass Type
7243 #ifndef PRODUCT
7244 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7245 st->print("aryklassptr:[");
7246 _elem->dump2(d, depth, st);
7247 _interfaces->dump(st);
7248 st->print(":%s", ptr_msg[_ptr]);
7249 if (_flat) st->print(":flat");
7250 if (_null_free) st->print(":null free");
7251 if (_atomic) st->print(":atomic");
7252 if (_refined_type) st->print(":refined_type");
7253 if (Verbose) {
7254 if (_not_flat) st->print(":not flat");
7255 if (_not_null_free) st->print(":nullable");
7256 }
7257 dump_offset(st);
7258 }
7259 #endif
7260
7261 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7262 const Type* elem = this->elem();
7263 dims = 1;
7264 while (elem->isa_aryklassptr()) {
7265 elem = elem->is_aryklassptr()->elem();
7266 dims++;
7267 }
7268 return elem;
7269 }
7270
7271 //=============================================================================
7272 // Convenience common pre-built types.
7273
7274 //------------------------------make-------------------------------------------
7275 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7276 const TypeTuple *range_sig, const TypeTuple *range_cc) {
7277 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7278 }
7279
7280 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7281 return make(domain, domain, range, range);
7282 }
7283
7284 //------------------------------osr_domain-----------------------------
7285 const TypeTuple* osr_domain() {
7286 const Type **fields = TypeTuple::fields(2);
7287 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7288 return TypeTuple::make(TypeFunc::Parms+1, fields);
7289 }
7290
7291 //------------------------------make-------------------------------------------
7292 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7293 Compile* C = Compile::current();
7294 const TypeFunc* tf = nullptr;
7295 if (!is_osr_compilation) {
7296 tf = C->last_tf(method); // check cache
7297 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7298 }
7299 // Inline types are not passed/returned by reference, instead each field of
7300 // the inline type is passed/returned as an argument. We maintain two views of
7301 // the argument/return list here: one based on the signature (with an inline
7302 // type argument/return as a single slot), one based on the actual calling
7303 // convention (with an inline type argument/return as a list of its fields).
7304 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7305 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7306 if (method != C->method() && method->get_Method()->mismatch()) {
7307 has_scalar_args = false;
7308 }
7309 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7310 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7311 ciSignature* sig = method->signature();
7312 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7313 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7314 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7315 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7316 if (!is_osr_compilation) {
7317 C->set_last_tf(method, tf); // fill cache
7318 }
7319 return tf;
7320 }
7321
7322 //------------------------------meet-------------------------------------------
7323 // Compute the MEET of two types. It returns a new Type object.
7324 const Type *TypeFunc::xmeet( const Type *t ) const {
7325 // Perform a fast test for common case; meeting the same types together.
7326 if( this == t ) return this; // Meeting same type-rep?
7327
7328 // Current "this->_base" is Func
7329 switch (t->base()) { // switch on original type
7330
7331 case Bottom: // Ye Olde Default
7332 return t;
7333
7334 default: // All else is a mistake
7335 typerr(t);
7336
7337 case Top:
7338 break;
7339 }
7340 return this; // Return the double constant
7341 }
7342
7343 //------------------------------xdual------------------------------------------
7344 // Dual: compute field-by-field dual
7345 const Type *TypeFunc::xdual() const {
7346 return this;
7347 }
7348
7349 //------------------------------eq---------------------------------------------
7350 // Structural equality check for Type representations
7351 bool TypeFunc::eq( const Type *t ) const {
7352 const TypeFunc *a = (const TypeFunc*)t;
7353 return _domain_sig == a->_domain_sig &&
7354 _domain_cc == a->_domain_cc &&
7355 _range_sig == a->_range_sig &&
7356 _range_cc == a->_range_cc;
7357 }
7358
7359 //------------------------------hash-------------------------------------------
7360 // Type-specific hashing function.
7361 uint TypeFunc::hash(void) const {
7362 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7363 }
7364
7365 //------------------------------dump2------------------------------------------
7366 // Dump Function Type
7367 #ifndef PRODUCT
7368 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7369 if( _range_sig->cnt() <= Parms )
7370 st->print("void");
7371 else {
7372 uint i;
7373 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7374 _range_sig->field_at(i)->dump2(d,depth,st);
7375 st->print("/");
7376 }
7377 _range_sig->field_at(i)->dump2(d,depth,st);
7378 }
7379 st->print(" ");
7380 st->print("( ");
7381 if( !depth || d[this] ) { // Check for recursive dump
7382 st->print("...)");
7383 return;
7384 }
7385 d.Insert((void*)this,(void*)this); // Stop recursion
7386 if (Parms < _domain_sig->cnt())
7387 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7388 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7389 st->print(", ");
7390 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7391 }
7392 st->print(" )");
7393 }
7394 #endif
7395
7396 //------------------------------singleton--------------------------------------
7397 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7398 // constants (Ldi nodes). Singletons are integer, float or double constants
7399 // or a single symbol.
7400 bool TypeFunc::singleton(void) const {
7401 return false; // Never a singleton
7402 }
7403
7404 bool TypeFunc::empty(void) const {
7405 return false; // Never empty
7406 }
7407
7408
7409 BasicType TypeFunc::return_type() const{
7410 if (range_sig()->cnt() == TypeFunc::Parms) {
7411 return T_VOID;
7412 }
7413 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7414 }
|