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 "precompiled.hpp"
26 #include "ci/ciMethodData.hpp"
27 #include "ci/ciTypeFlow.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.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/matcher.hpp"
39 #include "opto/node.hpp"
40 #include "opto/opcodes.hpp"
41 #include "opto/type.hpp"
42 #include "utilities/checkedCast.hpp"
43 #include "utilities/powerOfTwo.hpp"
44 #include "utilities/stringUtils.hpp"
45
46 // Portions of code courtesy of Clifford Click
47
48 // Optimization - Graph Style
49
50 // Dictionary of types shared among compilations.
51 Dict* Type::_shared_type_dict = nullptr;
52
53 // Array which maps compiler types to Basic Types
54 const Type::TypeInfo Type::_type_info[Type::lastype] = {
55 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
56 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
57 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
58 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
59 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
60 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
61 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
62 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
63 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
64 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
65 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
66
67 #if defined(PPC64)
68 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
69 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
70 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
71 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
206 case ciTypeFlow::StateVector::T_NULL:
207 assert(type == ciTypeFlow::StateVector::null_type(), "");
208 return TypePtr::NULL_PTR;
209
210 case ciTypeFlow::StateVector::T_LONG2:
211 // The ciTypeFlow pass pushes a long, then the half.
212 // We do the same.
213 assert(type == ciTypeFlow::StateVector::long2_type(), "");
214 return TypeInt::TOP;
215
216 case ciTypeFlow::StateVector::T_DOUBLE2:
217 // The ciTypeFlow pass pushes double, then the half.
218 // Our convention is the same.
219 assert(type == ciTypeFlow::StateVector::double2_type(), "");
220 return Type::TOP;
221
222 case T_ADDRESS:
223 assert(type->is_return_address(), "");
224 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
225
226 default:
227 // make sure we did not mix up the cases:
228 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
229 assert(type != ciTypeFlow::StateVector::top_type(), "");
230 assert(type != ciTypeFlow::StateVector::null_type(), "");
231 assert(type != ciTypeFlow::StateVector::long2_type(), "");
232 assert(type != ciTypeFlow::StateVector::double2_type(), "");
233 assert(!type->is_return_address(), "");
234
235 return Type::get_const_type(type);
236 }
237 }
238
239
240 //-----------------------make_from_constant------------------------------------
241 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
242 int stable_dimension, bool is_narrow_oop,
243 bool is_autobox_cache) {
244 switch (constant.basic_type()) {
245 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
512 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
513 ffalse[0] = Type::CONTROL;
514 ffalse[1] = Type::TOP;
515 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
516
517 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
518 fneither[0] = Type::TOP;
519 fneither[1] = Type::TOP;
520 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
521
522 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
523 ftrue[0] = Type::TOP;
524 ftrue[1] = Type::CONTROL;
525 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
526
527 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
528 floop[0] = Type::CONTROL;
529 floop[1] = TypeInt::INT;
530 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
531
532 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
533 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
534 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
535
536 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
537 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
538
539 const Type **fmembar = TypeTuple::fields(0);
540 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
541
542 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
543 fsc[0] = TypeInt::CC;
544 fsc[1] = Type::MEMORY;
545 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
546
547 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
548 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
549 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
550 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
551 false, 0, oopDesc::mark_offset_in_bytes());
552 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
553 false, 0, oopDesc::klass_offset_in_bytes());
554 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
555
556 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
557
558 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
559 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
560
561 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
562
563 mreg2type[Op_Node] = Type::BOTTOM;
564 mreg2type[Op_Set ] = 0;
565 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
566 mreg2type[Op_RegI] = TypeInt::INT;
567 mreg2type[Op_RegP] = TypePtr::BOTTOM;
568 mreg2type[Op_RegF] = Type::FLOAT;
569 mreg2type[Op_RegD] = Type::DOUBLE;
570 mreg2type[Op_RegL] = TypeLong::LONG;
571 mreg2type[Op_RegFlags] = TypeInt::CC;
572
573 GrowableArray<ciInstanceKlass*> array_interfaces;
574 array_interfaces.push(current->env()->Cloneable_klass());
575 array_interfaces.push(current->env()->Serializable_klass());
576 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
577 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
578
579 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
580
581 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
582
583 #ifdef _LP64
584 if (UseCompressedOops) {
585 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
586 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
587 } else
588 #endif
589 {
590 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
591 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
592 }
593 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
594 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
595 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
596 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
597 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
598 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
599 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
600
601 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
602 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
603 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
604 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
605 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
606 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
607 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
608 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
609 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
610 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
611 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
612 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
613
614 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
615 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
616
617 const Type **fi2c = TypeTuple::fields(2);
618 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
619 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
620 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
621
622 const Type **intpair = TypeTuple::fields(2);
623 intpair[0] = TypeInt::INT;
624 intpair[1] = TypeInt::INT;
625 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
626
627 const Type **longpair = TypeTuple::fields(2);
628 longpair[0] = TypeLong::LONG;
629 longpair[1] = TypeLong::LONG;
630 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
631
632 const Type **intccpair = TypeTuple::fields(2);
633 intccpair[0] = TypeInt::INT;
634 intccpair[1] = TypeInt::CC;
635 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
636
637 const Type **longccpair = TypeTuple::fields(2);
638 longccpair[0] = TypeLong::LONG;
639 longccpair[1] = TypeInt::CC;
640 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
641
642 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
643 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
644 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
645 _const_basic_type[T_CHAR] = TypeInt::CHAR;
646 _const_basic_type[T_BYTE] = TypeInt::BYTE;
647 _const_basic_type[T_SHORT] = TypeInt::SHORT;
648 _const_basic_type[T_INT] = TypeInt::INT;
649 _const_basic_type[T_LONG] = TypeLong::LONG;
650 _const_basic_type[T_FLOAT] = Type::FLOAT;
651 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
652 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
653 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
654 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
655 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
656 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
657
658 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
659 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
660 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
661 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
662 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
663 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
664 _zero_type[T_INT] = TypeInt::ZERO;
665 _zero_type[T_LONG] = TypeLong::ZERO;
666 _zero_type[T_FLOAT] = TypeF::ZERO;
667 _zero_type[T_DOUBLE] = TypeD::ZERO;
668 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
669 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
670 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
671 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
672
673 // get_zero_type() should not happen for T_CONFLICT
674 _zero_type[T_CONFLICT]= nullptr;
675
676 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
677 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
678
679 if (Matcher::supports_scalable_vector()) {
680 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
681 }
682
683 // Vector predefined types, it needs initialized _const_basic_type[].
684 if (Matcher::vector_size_supported(T_BYTE,4)) {
685 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
686 }
687 if (Matcher::vector_size_supported(T_FLOAT,2)) {
688 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
689 }
2106
2107 bool TypeLong::empty(void) const {
2108 return _lo > _hi;
2109 }
2110
2111 //=============================================================================
2112 // Convenience common pre-built types.
2113 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2114 const TypeTuple *TypeTuple::IFFALSE;
2115 const TypeTuple *TypeTuple::IFTRUE;
2116 const TypeTuple *TypeTuple::IFNEITHER;
2117 const TypeTuple *TypeTuple::LOOPBODY;
2118 const TypeTuple *TypeTuple::MEMBAR;
2119 const TypeTuple *TypeTuple::STORECONDITIONAL;
2120 const TypeTuple *TypeTuple::START_I2C;
2121 const TypeTuple *TypeTuple::INT_PAIR;
2122 const TypeTuple *TypeTuple::LONG_PAIR;
2123 const TypeTuple *TypeTuple::INT_CC_PAIR;
2124 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2125
2126 //------------------------------make-------------------------------------------
2127 // Make a TypeTuple from the range of a method signature
2128 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2129 ciType* return_type = sig->return_type();
2130 uint arg_cnt = return_type->size();
2131 const Type **field_array = fields(arg_cnt);
2132 switch (return_type->basic_type()) {
2133 case T_LONG:
2134 field_array[TypeFunc::Parms] = TypeLong::LONG;
2135 field_array[TypeFunc::Parms+1] = Type::HALF;
2136 break;
2137 case T_DOUBLE:
2138 field_array[TypeFunc::Parms] = Type::DOUBLE;
2139 field_array[TypeFunc::Parms+1] = Type::HALF;
2140 break;
2141 case T_OBJECT:
2142 case T_ARRAY:
2143 case T_BOOLEAN:
2144 case T_CHAR:
2145 case T_FLOAT:
2146 case T_BYTE:
2147 case T_SHORT:
2148 case T_INT:
2149 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2150 break;
2151 case T_VOID:
2152 break;
2153 default:
2154 ShouldNotReachHere();
2155 }
2156 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2157 }
2158
2159 // Make a TypeTuple from the domain of a method signature
2160 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2161 uint arg_cnt = sig->size();
2162
2163 uint pos = TypeFunc::Parms;
2164 const Type **field_array;
2165 if (recv != nullptr) {
2166 arg_cnt++;
2167 field_array = fields(arg_cnt);
2168 // Use get_const_type here because it respects UseUniqueSubclasses:
2169 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2170 } else {
2171 field_array = fields(arg_cnt);
2172 }
2173
2174 int i = 0;
2175 while (pos < TypeFunc::Parms + arg_cnt) {
2176 ciType* type = sig->type_at(i);
2177
2178 switch (type->basic_type()) {
2179 case T_LONG:
2180 field_array[pos++] = TypeLong::LONG;
2181 field_array[pos++] = Type::HALF;
2182 break;
2183 case T_DOUBLE:
2184 field_array[pos++] = Type::DOUBLE;
2185 field_array[pos++] = Type::HALF;
2186 break;
2187 case T_OBJECT:
2188 case T_ARRAY:
2189 case T_FLOAT:
2190 case T_INT:
2191 field_array[pos++] = get_const_type(type, interface_handling);
2192 break;
2193 case T_BOOLEAN:
2194 case T_CHAR:
2195 case T_BYTE:
2196 case T_SHORT:
2197 field_array[pos++] = TypeInt::INT;
2198 break;
2199 default:
2200 ShouldNotReachHere();
2201 }
2202 i++;
2203 }
2204
2205 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2206 }
2207
2208 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2209 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2210 }
2211
2212 //------------------------------fields-----------------------------------------
2213 // Subroutine call type with space allocated for argument types
2214 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2215 const Type **TypeTuple::fields( uint arg_cnt ) {
2216 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2217 flds[TypeFunc::Control ] = Type::CONTROL;
2218 flds[TypeFunc::I_O ] = Type::ABIO;
2219 flds[TypeFunc::Memory ] = Type::MEMORY;
2220 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2221 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2222
2223 return flds;
2318 if (_fields[i]->empty()) return true;
2319 }
2320 return false;
2321 }
2322
2323 //=============================================================================
2324 // Convenience common pre-built types.
2325
2326 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2327 // Certain normalizations keep us sane when comparing types.
2328 // We do not want arrayOop variables to differ only by the wideness
2329 // of their index types. Pick minimum wideness, since that is the
2330 // forced wideness of small ranges anyway.
2331 if (size->_widen != Type::WidenMin)
2332 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2333 else
2334 return size;
2335 }
2336
2337 //------------------------------make-------------------------------------------
2338 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2339 if (UseCompressedOops && elem->isa_oopptr()) {
2340 elem = elem->make_narrowoop();
2341 }
2342 size = normalize_array_size(size);
2343 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2344 }
2345
2346 //------------------------------meet-------------------------------------------
2347 // Compute the MEET of two types. It returns a new Type object.
2348 const Type *TypeAry::xmeet( const Type *t ) const {
2349 // Perform a fast test for common case; meeting the same types together.
2350 if( this == t ) return this; // Meeting same type-rep?
2351
2352 // Current "this->_base" is Ary
2353 switch (t->base()) { // switch on original type
2354
2355 case Bottom: // Ye Olde Default
2356 return t;
2357
2358 default: // All else is a mistake
2359 typerr(t);
2360
2361 case Array: { // Meeting 2 arrays?
2362 const TypeAry *a = t->is_ary();
2363 return TypeAry::make(_elem->meet_speculative(a->_elem),
2364 _size->xmeet(a->_size)->is_int(),
2365 _stable && a->_stable);
2366 }
2367 case Top:
2368 break;
2369 }
2370 return this; // Return the double constant
2371 }
2372
2373 //------------------------------xdual------------------------------------------
2374 // Dual: compute field-by-field dual
2375 const Type *TypeAry::xdual() const {
2376 const TypeInt* size_dual = _size->dual()->is_int();
2377 size_dual = normalize_array_size(size_dual);
2378 return new TypeAry(_elem->dual(), size_dual, !_stable);
2379 }
2380
2381 //------------------------------eq---------------------------------------------
2382 // Structural equality check for Type representations
2383 bool TypeAry::eq( const Type *t ) const {
2384 const TypeAry *a = (const TypeAry*)t;
2385 return _elem == a->_elem &&
2386 _stable == a->_stable &&
2387 _size == a->_size;
2388 }
2389
2390 //------------------------------hash-------------------------------------------
2391 // Type-specific hashing function.
2392 uint TypeAry::hash(void) const {
2393 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);
2394 }
2395
2396 /**
2397 * Return same type without a speculative part in the element
2398 */
2399 const TypeAry* TypeAry::remove_speculative() const {
2400 return make(_elem->remove_speculative(), _size, _stable);
2401 }
2402
2403 /**
2404 * Return same type with cleaned up speculative part of element
2405 */
2406 const Type* TypeAry::cleanup_speculative() const {
2407 return make(_elem->cleanup_speculative(), _size, _stable);
2408 }
2409
2410 /**
2411 * Return same type but with a different inline depth (used for speculation)
2412 *
2413 * @param depth depth to meet with
2414 */
2415 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2416 if (!UseInlineDepthForSpeculativeTypes) {
2417 return this;
2418 }
2419 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2420 }
2421
2422 //------------------------------dump2------------------------------------------
2423 #ifndef PRODUCT
2424 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2425 if (_stable) st->print("stable:");
2426 _elem->dump2(d, depth, st);
2427 st->print("[");
2428 _size->dump2(d, depth, st);
2429 st->print("]");
2430 }
2431 #endif
2432
2433 //------------------------------singleton--------------------------------------
2434 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2435 // constants (Ldi nodes). Singletons are integer, float or double constants
2436 // or a single symbol.
2437 bool TypeAry::singleton(void) const {
2438 return false; // Never a singleton
2439 }
2440
2441 bool TypeAry::empty(void) const {
2442 return _elem->empty() || _size->empty();
2443 }
2444
2445 //--------------------------ary_must_be_exact----------------------------------
2446 bool TypeAry::ary_must_be_exact() const {
2447 // This logic looks at the element type of an array, and returns true
2448 // if the element type is either a primitive or a final instance class.
2449 // In such cases, an array built on this ary must have no subclasses.
2450 if (_elem == BOTTOM) return false; // general array not exact
2451 if (_elem == TOP ) return false; // inverted general array not exact
2452 const TypeOopPtr* toop = nullptr;
2453 if (UseCompressedOops && _elem->isa_narrowoop()) {
2454 toop = _elem->make_ptr()->isa_oopptr();
2455 } else {
2456 toop = _elem->isa_oopptr();
2457 }
2458 if (!toop) return true; // a primitive type, like int
2459 if (!toop->is_loaded()) return false; // unloaded class
2460 const TypeInstPtr* tinst;
2461 if (_elem->isa_narrowoop())
2462 tinst = _elem->make_ptr()->isa_instptr();
2463 else
2464 tinst = _elem->isa_instptr();
2465 if (tinst)
2466 return tinst->instance_klass()->is_final();
2467 const TypeAryPtr* tap;
2468 if (_elem->isa_narrowoop())
2469 tap = _elem->make_ptr()->isa_aryptr();
2470 else
2471 tap = _elem->isa_aryptr();
2472 if (tap)
2473 return tap->ary()->ary_must_be_exact();
2474 return false;
2475 }
2476
2477 //==============================TypeVect=======================================
2478 // Convenience common pre-built types.
2479 const TypeVect *TypeVect::VECTA = nullptr; // vector length agnostic
2480 const TypeVect *TypeVect::VECTS = nullptr; // 32-bit vectors
2481 const TypeVect *TypeVect::VECTD = nullptr; // 64-bit vectors
2482 const TypeVect *TypeVect::VECTX = nullptr; // 128-bit vectors
2483 const TypeVect *TypeVect::VECTY = nullptr; // 256-bit vectors
2484 const TypeVect *TypeVect::VECTZ = nullptr; // 512-bit vectors
2485 const TypeVect *TypeVect::VECTMASK = nullptr; // predicate/mask vector
2486
2642
2643 //=============================================================================
2644 // Convenience common pre-built types.
2645 const TypePtr *TypePtr::NULL_PTR;
2646 const TypePtr *TypePtr::NOTNULL;
2647 const TypePtr *TypePtr::BOTTOM;
2648
2649 //------------------------------meet-------------------------------------------
2650 // Meet over the PTR enum
2651 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2652 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2653 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2654 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2655 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2656 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2657 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2658 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2659 };
2660
2661 //------------------------------make-------------------------------------------
2662 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2663 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2664 }
2665
2666 //------------------------------cast_to_ptr_type-------------------------------
2667 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2668 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2669 if( ptr == _ptr ) return this;
2670 return make(_base, ptr, _offset, _speculative, _inline_depth);
2671 }
2672
2673 //------------------------------get_con----------------------------------------
2674 intptr_t TypePtr::get_con() const {
2675 assert( _ptr == Null, "" );
2676 return _offset;
2677 }
2678
2679 //------------------------------meet-------------------------------------------
2680 // Compute the MEET of two types. It returns a new Type object.
2681 const Type *TypePtr::xmeet(const Type *t) const {
2682 const Type* res = xmeet_helper(t);
2683 if (res->isa_ptr() == nullptr) {
2684 return res;
2685 }
2686
2687 const TypePtr* res_ptr = res->is_ptr();
2688 if (res_ptr->speculative() != nullptr) {
2689 // type->speculative() is null means that speculation is no better
2690 // than type, i.e. type->speculative() == type. So there are 2
2691 // ways to represent the fact that we have no useful speculative
2692 // data and we should use a single one to be able to test for
2693 // equality between types. Check whether type->speculative() ==
2694 // type and set speculative to null if it is the case.
2695 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2696 return res_ptr->remove_speculative();
2727 int depth = meet_inline_depth(tp->inline_depth());
2728 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2729 }
2730 case RawPtr: // For these, flip the call around to cut down
2731 case OopPtr:
2732 case InstPtr: // on the cases I have to handle.
2733 case AryPtr:
2734 case MetadataPtr:
2735 case KlassPtr:
2736 case InstKlassPtr:
2737 case AryKlassPtr:
2738 return t->xmeet(this); // Call in reverse direction
2739 default: // All else is a mistake
2740 typerr(t);
2741
2742 }
2743 return this;
2744 }
2745
2746 //------------------------------meet_offset------------------------------------
2747 int TypePtr::meet_offset( int offset ) const {
2748 // Either is 'TOP' offset? Return the other offset!
2749 if( _offset == OffsetTop ) return offset;
2750 if( offset == OffsetTop ) return _offset;
2751 // If either is different, return 'BOTTOM' offset
2752 if( _offset != offset ) return OffsetBot;
2753 return _offset;
2754 }
2755
2756 //------------------------------dual_offset------------------------------------
2757 int TypePtr::dual_offset( ) const {
2758 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2759 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2760 return _offset; // Map everything else into self
2761 }
2762
2763 //------------------------------xdual------------------------------------------
2764 // Dual: compute field-by-field dual
2765 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2766 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2767 };
2768 const Type *TypePtr::xdual() const {
2769 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2770 }
2771
2772 //------------------------------xadd_offset------------------------------------
2773 int TypePtr::xadd_offset( intptr_t offset ) const {
2774 // Adding to 'TOP' offset? Return 'TOP'!
2775 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2776 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2777 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2778 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2779 offset += (intptr_t)_offset;
2780 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2781
2782 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2783 // It is possible to construct a negative offset during PhaseCCP
2784
2785 return (int)offset; // Sum valid offsets
2786 }
2787
2788 //------------------------------add_offset-------------------------------------
2789 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2790 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2791 }
2792
2793 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2794 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2795 }
2796
2797 //------------------------------eq---------------------------------------------
2798 // Structural equality check for Type representations
2799 bool TypePtr::eq( const Type *t ) const {
2800 const TypePtr *a = (const TypePtr*)t;
2801 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2802 }
2803
2804 //------------------------------hash-------------------------------------------
2805 // Type-specific hashing function.
2806 uint TypePtr::hash(void) const {
2807 return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2808 }
2809
2810 /**
2811 * Return same type without a speculative part
2812 */
2813 const TypePtr* TypePtr::remove_speculative() const {
2814 if (_speculative == nullptr) {
2815 return this;
2816 }
2817 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2818 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2819 }
2820
2821 /**
2822 * Return same type but drop speculative part if we know we won't use
2823 * it
2824 */
2825 const Type* TypePtr::cleanup_speculative() const {
2826 if (speculative() == nullptr) {
2827 return this;
3053 }
3054 // We already know the speculative type is always null
3055 if (speculative_always_null()) {
3056 return false;
3057 }
3058 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3059 return false;
3060 }
3061 return true;
3062 }
3063
3064 //------------------------------dump2------------------------------------------
3065 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3066 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3067 };
3068
3069 #ifndef PRODUCT
3070 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3071 if( _ptr == Null ) st->print("null");
3072 else st->print("%s *", ptr_msg[_ptr]);
3073 if( _offset == OffsetTop ) st->print("+top");
3074 else if( _offset == OffsetBot ) st->print("+bot");
3075 else if( _offset ) st->print("+%d", _offset);
3076 dump_inline_depth(st);
3077 dump_speculative(st);
3078 }
3079
3080 /**
3081 *dump the speculative part of the type
3082 */
3083 void TypePtr::dump_speculative(outputStream *st) const {
3084 if (_speculative != nullptr) {
3085 st->print(" (speculative=");
3086 _speculative->dump_on(st);
3087 st->print(")");
3088 }
3089 }
3090
3091 /**
3092 *dump the inline depth of the type
3093 */
3094 void TypePtr::dump_inline_depth(outputStream *st) const {
3095 if (_inline_depth != InlineDepthBottom) {
3096 if (_inline_depth == InlineDepthTop) {
3097 st->print(" (inline_depth=InlineDepthTop)");
3098 } else {
3099 st->print(" (inline_depth=%d)", _inline_depth);
3100 }
3101 }
3102 }
3103 #endif
3104
3105 //------------------------------singleton--------------------------------------
3106 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3107 // constants
3108 bool TypePtr::singleton(void) const {
3109 // TopPTR, Null, AnyNull, Constant are all singletons
3110 return (_offset != OffsetBot) && !below_centerline(_ptr);
3111 }
3112
3113 bool TypePtr::empty(void) const {
3114 return (_offset == OffsetTop) || above_centerline(_ptr);
3115 }
3116
3117 //=============================================================================
3118 // Convenience common pre-built types.
3119 const TypeRawPtr *TypeRawPtr::BOTTOM;
3120 const TypeRawPtr *TypeRawPtr::NOTNULL;
3121
3122 //------------------------------make-------------------------------------------
3123 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3124 assert( ptr != Constant, "what is the constant?" );
3125 assert( ptr != Null, "Use TypePtr for null" );
3126 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3127 }
3128
3129 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3130 assert( bits, "Use TypePtr for null" );
3131 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3132 }
3133
3134 //------------------------------cast_to_ptr_type-------------------------------
3486 void TypeInterfaces::verify_is_loaded() const {
3487 for (int i = 0; i < _list.length(); i++) {
3488 ciKlass* interface = _list.at(i);
3489 assert(interface->is_loaded(), "Interface not loaded");
3490 }
3491 }
3492 #endif
3493
3494 // Can't be implemented because there's no way to know if the type is above or below the center line.
3495 const Type* TypeInterfaces::xmeet(const Type* t) const {
3496 ShouldNotReachHere();
3497 return Type::xmeet(t);
3498 }
3499
3500 bool TypeInterfaces::singleton(void) const {
3501 ShouldNotReachHere();
3502 return Type::singleton();
3503 }
3504
3505 //------------------------------TypeOopPtr-------------------------------------
3506 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3507 int instance_id, const TypePtr* speculative, int inline_depth)
3508 : TypePtr(t, ptr, offset, speculative, inline_depth),
3509 _const_oop(o), _klass(k),
3510 _interfaces(interfaces),
3511 _klass_is_exact(xk),
3512 _is_ptr_to_narrowoop(false),
3513 _is_ptr_to_narrowklass(false),
3514 _is_ptr_to_boxed_value(false),
3515 _instance_id(instance_id) {
3516 #ifdef ASSERT
3517 if (klass() != nullptr && klass()->is_loaded()) {
3518 interfaces->verify_is_loaded();
3519 }
3520 #endif
3521 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3522 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3523 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3524 }
3525 #ifdef _LP64
3526 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3527 if (_offset == oopDesc::klass_offset_in_bytes()) {
3528 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3529 } else if (klass() == nullptr) {
3530 // Array with unknown body type
3531 assert(this->isa_aryptr(), "only arrays without klass");
3532 _is_ptr_to_narrowoop = UseCompressedOops;
3533 } else if (this->isa_aryptr()) {
3534 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3535 _offset != arrayOopDesc::length_offset_in_bytes());
3536 } else if (klass()->is_instance_klass()) {
3537 ciInstanceKlass* ik = klass()->as_instance_klass();
3538 if (this->isa_klassptr()) {
3539 // Perm objects don't use compressed references
3540 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3541 // unsafe access
3542 _is_ptr_to_narrowoop = UseCompressedOops;
3543 } else {
3544 assert(this->isa_instptr(), "must be an instance ptr.");
3545
3546 if (klass() == ciEnv::current()->Class_klass() &&
3547 (_offset == java_lang_Class::klass_offset() ||
3548 _offset == java_lang_Class::array_klass_offset())) {
3549 // Special hidden fields from the Class.
3550 assert(this->isa_instptr(), "must be an instance ptr.");
3551 _is_ptr_to_narrowoop = false;
3552 } else if (klass() == ciEnv::current()->Class_klass() &&
3553 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3554 // Static fields
3555 ciField* field = nullptr;
3556 if (const_oop() != nullptr) {
3557 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3558 field = k->get_field_by_offset(_offset, true);
3559 }
3560 if (field != nullptr) {
3561 BasicType basic_elem_type = field->layout_type();
3562 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3563 } else {
3564 // unsafe access
3565 _is_ptr_to_narrowoop = UseCompressedOops;
3566 }
3567 } else {
3568 // Instance fields which contains a compressed oop references.
3569 ciField* field = ik->get_field_by_offset(_offset, false);
3570 if (field != nullptr) {
3571 BasicType basic_elem_type = field->layout_type();
3572 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3573 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3574 // Compile::find_alias_type() cast exactness on all types to verify
3575 // that it does not affect alias type.
3576 _is_ptr_to_narrowoop = UseCompressedOops;
3577 } else {
3578 // Type for the copy start in LibraryCallKit::inline_native_clone().
3579 _is_ptr_to_narrowoop = UseCompressedOops;
3580 }
3581 }
3582 }
3583 }
3584 }
3585 #endif
3586 }
3587
3588 //------------------------------make-------------------------------------------
3589 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3590 const TypePtr* speculative, int inline_depth) {
3591 assert(ptr != Constant, "no constant generic pointers");
3592 ciKlass* k = Compile::current()->env()->Object_klass();
3593 bool xk = false;
3594 ciObject* o = nullptr;
3595 const TypeInterfaces* interfaces = TypeInterfaces::make();
3596 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3597 }
3598
3599
3600 //------------------------------cast_to_ptr_type-------------------------------
3601 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3602 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3603 if( ptr == _ptr ) return this;
3604 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3605 }
3606
3607 //-----------------------------cast_to_instance_id----------------------------
3608 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3609 // There are no instances of a general oop.
3610 // Return self unchanged.
3611 return this;
3612 }
3613
3614 //-----------------------------cast_to_exactness-------------------------------
3615 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3616 // There is no such thing as an exact general oop.
3617 // Return self unchanged.
3618 return this;
3619 }
3620
3621
3622 //------------------------------as_klass_type----------------------------------
3623 // Return the klass type corresponding to this instance or array type.
3624 // It is the type that is loaded from an object of this type.
3625 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3626 ShouldNotReachHere();
3627 return nullptr;
3628 }
3629
3630 //------------------------------meet-------------------------------------------
3631 // Compute the MEET of two types. It returns a new Type object.
3632 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3633 // Perform a fast test for common case; meeting the same types together.
3634 if( this == t ) return this; // Meeting same type-rep?
3635
3636 // Current "this->_base" is OopPtr
3637 switch (t->base()) { // switch on original type
3638
3639 case Int: // Mixing ints & oops happens when javac
3640 case Long: // reuses local variables
3641 case FloatTop:
3647 case NarrowOop:
3648 case NarrowKlass:
3649 case Bottom: // Ye Olde Default
3650 return Type::BOTTOM;
3651 case Top:
3652 return this;
3653
3654 default: // All else is a mistake
3655 typerr(t);
3656
3657 case RawPtr:
3658 case MetadataPtr:
3659 case KlassPtr:
3660 case InstKlassPtr:
3661 case AryKlassPtr:
3662 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3663
3664 case AnyPtr: {
3665 // Found an AnyPtr type vs self-OopPtr type
3666 const TypePtr *tp = t->is_ptr();
3667 int offset = meet_offset(tp->offset());
3668 PTR ptr = meet_ptr(tp->ptr());
3669 const TypePtr* speculative = xmeet_speculative(tp);
3670 int depth = meet_inline_depth(tp->inline_depth());
3671 switch (tp->ptr()) {
3672 case Null:
3673 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3674 // else fall through:
3675 case TopPTR:
3676 case AnyNull: {
3677 int instance_id = meet_instance_id(InstanceTop);
3678 return make(ptr, offset, instance_id, speculative, depth);
3679 }
3680 case BotPTR:
3681 case NotNull:
3682 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3683 default: typerr(t);
3684 }
3685 }
3686
3687 case OopPtr: { // Meeting to other OopPtrs
3689 int instance_id = meet_instance_id(tp->instance_id());
3690 const TypePtr* speculative = xmeet_speculative(tp);
3691 int depth = meet_inline_depth(tp->inline_depth());
3692 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3693 }
3694
3695 case InstPtr: // For these, flip the call around to cut down
3696 case AryPtr:
3697 return t->xmeet(this); // Call in reverse direction
3698
3699 } // End of switch
3700 return this; // Return the double constant
3701 }
3702
3703
3704 //------------------------------xdual------------------------------------------
3705 // Dual of a pure heap pointer. No relevant klass or oop information.
3706 const Type *TypeOopPtr::xdual() const {
3707 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3708 assert(const_oop() == nullptr, "no constants here");
3709 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3710 }
3711
3712 //--------------------------make_from_klass_common-----------------------------
3713 // Computes the element-type given a klass.
3714 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3715 if (klass->is_instance_klass()) {
3716 Compile* C = Compile::current();
3717 Dependencies* deps = C->dependencies();
3718 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3719 // Element is an instance
3720 bool klass_is_exact = false;
3721 if (klass->is_loaded()) {
3722 // Try to set klass_is_exact.
3723 ciInstanceKlass* ik = klass->as_instance_klass();
3724 klass_is_exact = ik->is_final();
3725 if (!klass_is_exact && klass_change
3726 && deps != nullptr && UseUniqueSubclasses) {
3727 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3728 if (sub != nullptr) {
3729 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3730 klass = ik = sub;
3731 klass_is_exact = sub->is_final();
3732 }
3733 }
3734 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3735 !ik->is_interface() && !ik->has_subklass()) {
3736 // Add a dependence; if concrete subclass added we need to recompile
3737 deps->assert_leaf_type(ik);
3738 klass_is_exact = true;
3739 }
3740 }
3741 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3742 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3743 } else if (klass->is_obj_array_klass()) {
3744 // Element is an object array. Recursively call ourself.
3745 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3746 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3747 bool xk = etype->klass_is_exact();
3748 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3749 // We used to pass NotNull in here, asserting that the sub-arrays
3750 // are all not-null. This is not true in generally, as code can
3751 // slam nulls down in the subarrays.
3752 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3753 return arr;
3754 } else if (klass->is_type_array_klass()) {
3755 // Element is an typeArray
3756 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3757 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3758 // We used to pass NotNull in here, asserting that the array pointer
3759 // is not-null. That was not true in general.
3760 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3761 return arr;
3762 } else {
3763 ShouldNotReachHere();
3764 return nullptr;
3765 }
3766 }
3767
3768 //------------------------------make_from_constant-----------------------------
3769 // Make a java pointer from an oop constant
3770 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3771 assert(!o->is_null_object(), "null object not yet handled here.");
3772
3773 const bool make_constant = require_constant || o->should_be_constant();
3774
3775 ciKlass* klass = o->klass();
3776 if (klass->is_instance_klass()) {
3777 // Element is an instance
3778 if (make_constant) {
3779 return TypeInstPtr::make(o);
3780 } else {
3781 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3782 }
3783 } else if (klass->is_obj_array_klass()) {
3784 // Element is an object array. Recursively call ourself.
3785 const TypeOopPtr *etype =
3786 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3787 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3788 // We used to pass NotNull in here, asserting that the sub-arrays
3789 // are all not-null. This is not true in generally, as code can
3790 // slam nulls down in the subarrays.
3791 if (make_constant) {
3792 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3793 } else {
3794 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3795 }
3796 } else if (klass->is_type_array_klass()) {
3797 // Element is an typeArray
3798 const Type* etype =
3799 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3800 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3801 // We used to pass NotNull in here, asserting that the array pointer
3802 // is not-null. That was not true in general.
3803 if (make_constant) {
3804 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3805 } else {
3806 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3807 }
3808 }
3809
3810 fatal("unhandled object type");
3811 return nullptr;
3812 }
3813
3814 //------------------------------get_con----------------------------------------
3815 intptr_t TypeOopPtr::get_con() const {
3816 assert( _ptr == Null || _ptr == Constant, "" );
3817 assert( _offset >= 0, "" );
3818
3819 if (_offset != 0) {
3820 // After being ported to the compiler interface, the compiler no longer
3821 // directly manipulates the addresses of oops. Rather, it only has a pointer
3822 // to a handle at compile time. This handle is embedded in the generated
3823 // code and dereferenced at the time the nmethod is made. Until that time,
3824 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3825 // have access to the addresses!). This does not seem to currently happen,
3826 // but this assertion here is to help prevent its occurrence.
3827 tty->print_cr("Found oop constant with non-zero offset");
3828 ShouldNotReachHere();
3829 }
3830
3831 return (intptr_t)const_oop()->constant_encoding();
3832 }
3833
3834
3835 //-----------------------------filter------------------------------------------
3836 // Do not allow interface-vs.-noninterface joins to collapse to top.
3837 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3838
3839 const Type* ft = join_helper(kills, include_speculative);
3860 } else {
3861 return one->equals(two) && TypePtr::eq(t);
3862 }
3863 }
3864
3865 //------------------------------hash-------------------------------------------
3866 // Type-specific hashing function.
3867 uint TypeOopPtr::hash(void) const {
3868 return
3869 (uint)(const_oop() ? const_oop()->hash() : 0) +
3870 (uint)_klass_is_exact +
3871 (uint)_instance_id + TypePtr::hash();
3872 }
3873
3874 //------------------------------dump2------------------------------------------
3875 #ifndef PRODUCT
3876 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3877 st->print("oopptr:%s", ptr_msg[_ptr]);
3878 if( _klass_is_exact ) st->print(":exact");
3879 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3880 switch( _offset ) {
3881 case OffsetTop: st->print("+top"); break;
3882 case OffsetBot: st->print("+any"); break;
3883 case 0: break;
3884 default: st->print("+%d",_offset); break;
3885 }
3886 if (_instance_id == InstanceTop)
3887 st->print(",iid=top");
3888 else if (_instance_id != InstanceBot)
3889 st->print(",iid=%d",_instance_id);
3890
3891 dump_inline_depth(st);
3892 dump_speculative(st);
3893 }
3894 #endif
3895
3896 //------------------------------singleton--------------------------------------
3897 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3898 // constants
3899 bool TypeOopPtr::singleton(void) const {
3900 // detune optimizer to not generate constant oop + constant offset as a constant!
3901 // TopPTR, Null, AnyNull, Constant are all singletons
3902 return (_offset == 0) && !below_centerline(_ptr);
3903 }
3904
3905 //------------------------------add_offset-------------------------------------
3906 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3907 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3908 }
3909
3910 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3911 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3912 }
3913
3914 /**
3915 * Return same type without a speculative part
3916 */
3917 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3918 if (_speculative == nullptr) {
3919 return this;
3920 }
3921 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3922 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3923 }
3924
3925 /**
3926 * Return same type but drop speculative part if we know we won't use
3927 * it
3928 */
3929 const Type* TypeOopPtr::cleanup_speculative() const {
3930 // If the klass is exact and the ptr is not null then there's
3931 // nothing that the speculative type can help us with
4004 const TypeInstPtr *TypeInstPtr::BOTTOM;
4005 const TypeInstPtr *TypeInstPtr::MIRROR;
4006 const TypeInstPtr *TypeInstPtr::MARK;
4007 const TypeInstPtr *TypeInstPtr::KLASS;
4008
4009 // Is there a single ciKlass* that can represent that type?
4010 ciKlass* TypeInstPtr::exact_klass_helper() const {
4011 if (_interfaces->empty()) {
4012 return _klass;
4013 }
4014 if (_klass != ciEnv::current()->Object_klass()) {
4015 if (_interfaces->eq(_klass->as_instance_klass())) {
4016 return _klass;
4017 }
4018 return nullptr;
4019 }
4020 return _interfaces->exact_klass();
4021 }
4022
4023 //------------------------------TypeInstPtr-------------------------------------
4024 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4025 int instance_id, const TypePtr* speculative, int inline_depth)
4026 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
4027 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4028 assert(k != nullptr &&
4029 (k->is_loaded() || o == nullptr),
4030 "cannot have constants with non-loaded klass");
4031 };
4032
4033 //------------------------------make-------------------------------------------
4034 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4035 ciKlass* k,
4036 const TypeInterfaces* interfaces,
4037 bool xk,
4038 ciObject* o,
4039 int offset,
4040 int instance_id,
4041 const TypePtr* speculative,
4042 int inline_depth) {
4043 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4044 // Either const_oop() is null or else ptr is Constant
4045 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4046 "constant pointers must have a value supplied" );
4047 // Ptr is never Null
4048 assert( ptr != Null, "null pointers are not typed" );
4049
4050 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4051 if (ptr == Constant) {
4052 // Note: This case includes meta-object constants, such as methods.
4053 xk = true;
4054 } else if (k->is_loaded()) {
4055 ciInstanceKlass* ik = k->as_instance_klass();
4056 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4057 assert(!ik->is_interface(), "no interface here");
4058 if (xk && ik->is_interface()) xk = false; // no exact interface
4059 }
4060
4061 // Now hash this baby
4062 TypeInstPtr *result =
4063 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4064
4065 return result;
4066 }
4067
4068 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4069 if (k->is_instance_klass()) {
4070 if (k->is_loaded()) {
4071 if (k->is_interface() && interface_handling == ignore_interfaces) {
4072 assert(interface, "no interface expected");
4073 k = ciEnv::current()->Object_klass();
4074 const TypeInterfaces* interfaces = TypeInterfaces::make();
4075 return interfaces;
4076 }
4077 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4078 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4079 if (k->is_interface()) {
4080 assert(interface, "no interface expected");
4081 k = ciEnv::current()->Object_klass();
4082 } else {
4083 assert(klass, "no instance klass expected");
4109 switch (bt) {
4110 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4111 case T_INT: return TypeInt::make(constant.as_int());
4112 case T_CHAR: return TypeInt::make(constant.as_char());
4113 case T_BYTE: return TypeInt::make(constant.as_byte());
4114 case T_SHORT: return TypeInt::make(constant.as_short());
4115 case T_FLOAT: return TypeF::make(constant.as_float());
4116 case T_DOUBLE: return TypeD::make(constant.as_double());
4117 case T_LONG: return TypeLong::make(constant.as_long());
4118 default: break;
4119 }
4120 fatal("Invalid boxed value type '%s'", type2name(bt));
4121 return nullptr;
4122 }
4123
4124 //------------------------------cast_to_ptr_type-------------------------------
4125 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4126 if( ptr == _ptr ) return this;
4127 // Reconstruct _sig info here since not a problem with later lazy
4128 // construction, _sig will show up on demand.
4129 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4130 }
4131
4132
4133 //-----------------------------cast_to_exactness-------------------------------
4134 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4135 if( klass_is_exact == _klass_is_exact ) return this;
4136 if (!_klass->is_loaded()) return this;
4137 ciInstanceKlass* ik = _klass->as_instance_klass();
4138 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4139 assert(!ik->is_interface(), "no interface here");
4140 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4141 }
4142
4143 //-----------------------------cast_to_instance_id----------------------------
4144 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4145 if( instance_id == _instance_id ) return this;
4146 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4147 }
4148
4149 //------------------------------xmeet_unloaded---------------------------------
4150 // Compute the MEET of two InstPtrs when at least one is unloaded.
4151 // Assume classes are different since called after check for same name/class-loader
4152 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4153 int off = meet_offset(tinst->offset());
4154 PTR ptr = meet_ptr(tinst->ptr());
4155 int instance_id = meet_instance_id(tinst->instance_id());
4156 const TypePtr* speculative = xmeet_speculative(tinst);
4157 int depth = meet_inline_depth(tinst->inline_depth());
4158
4159 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4160 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4161 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4162 //
4163 // Meet unloaded class with java/lang/Object
4164 //
4165 // Meet
4166 // | Unloaded Class
4167 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4168 // ===================================================================
4169 // TOP | ..........................Unloaded......................|
4170 // AnyNull | U-AN |................Unloaded......................|
4171 // Constant | ... O-NN .................................. | O-BOT |
4172 // NotNull | ... O-NN .................................. | O-BOT |
4173 // BOTTOM | ........................Object-BOTTOM ..................|
4174 //
4175 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4176 //
4177 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4178 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4179 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM; }
4180 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4181 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM; }
4182 else { return TypeInstPtr::NOTNULL; }
4183 }
4184 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4185
4186 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4187 }
4188
4189 // Both are unloaded, not the same class, not Object
4190 // Or meet unloaded with a different loaded class, not java/lang/Object
4191 if (ptr != TypePtr::BotPTR) {
4192 return TypeInstPtr::NOTNULL;
4193 }
4194 return TypeInstPtr::BOTTOM;
4195 }
4196
4197
4198 //------------------------------meet-------------------------------------------
4219 case Top:
4220 return this;
4221
4222 default: // All else is a mistake
4223 typerr(t);
4224
4225 case MetadataPtr:
4226 case KlassPtr:
4227 case InstKlassPtr:
4228 case AryKlassPtr:
4229 case RawPtr: return TypePtr::BOTTOM;
4230
4231 case AryPtr: { // All arrays inherit from Object class
4232 // Call in reverse direction to avoid duplication
4233 return t->is_aryptr()->xmeet_helper(this);
4234 }
4235
4236 case OopPtr: { // Meeting to OopPtrs
4237 // Found a OopPtr type vs self-InstPtr type
4238 const TypeOopPtr *tp = t->is_oopptr();
4239 int offset = meet_offset(tp->offset());
4240 PTR ptr = meet_ptr(tp->ptr());
4241 switch (tp->ptr()) {
4242 case TopPTR:
4243 case AnyNull: {
4244 int instance_id = meet_instance_id(InstanceTop);
4245 const TypePtr* speculative = xmeet_speculative(tp);
4246 int depth = meet_inline_depth(tp->inline_depth());
4247 return make(ptr, klass(), _interfaces, klass_is_exact(),
4248 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4249 }
4250 case NotNull:
4251 case BotPTR: {
4252 int instance_id = meet_instance_id(tp->instance_id());
4253 const TypePtr* speculative = xmeet_speculative(tp);
4254 int depth = meet_inline_depth(tp->inline_depth());
4255 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4256 }
4257 default: typerr(t);
4258 }
4259 }
4260
4261 case AnyPtr: { // Meeting to AnyPtrs
4262 // Found an AnyPtr type vs self-InstPtr type
4263 const TypePtr *tp = t->is_ptr();
4264 int offset = meet_offset(tp->offset());
4265 PTR ptr = meet_ptr(tp->ptr());
4266 int instance_id = meet_instance_id(InstanceTop);
4267 const TypePtr* speculative = xmeet_speculative(tp);
4268 int depth = meet_inline_depth(tp->inline_depth());
4269 switch (tp->ptr()) {
4270 case Null:
4271 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4272 // else fall through to AnyNull
4273 case TopPTR:
4274 case AnyNull: {
4275 return make(ptr, klass(), _interfaces, klass_is_exact(),
4276 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4277 }
4278 case NotNull:
4279 case BotPTR:
4280 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4281 default: typerr(t);
4282 }
4283 }
4284
4285 /*
4286 A-top }
4287 / | \ } Tops
4288 B-top A-any C-top }
4289 | / | \ | } Any-nulls
4290 B-any | C-any }
4291 | | |
4292 B-con A-con C-con } constants; not comparable across classes
4293 | | |
4294 B-not | C-not }
4295 | \ | / | } not-nulls
4296 B-bot A-not C-bot }
4297 \ | / } Bottoms
4298 A-bot }
4299 */
4300
4301 case InstPtr: { // Meeting 2 Oops?
4302 // Found an InstPtr sub-type vs self-InstPtr type
4303 const TypeInstPtr *tinst = t->is_instptr();
4304 int off = meet_offset(tinst->offset());
4305 PTR ptr = meet_ptr(tinst->ptr());
4306 int instance_id = meet_instance_id(tinst->instance_id());
4307 const TypePtr* speculative = xmeet_speculative(tinst);
4308 int depth = meet_inline_depth(tinst->inline_depth());
4309 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4310
4311 ciKlass* tinst_klass = tinst->klass();
4312 ciKlass* this_klass = klass();
4313
4314 ciKlass* res_klass = nullptr;
4315 bool res_xk = false;
4316 const Type* res;
4317 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4318
4319 if (kind == UNLOADED) {
4320 // One of these classes has not been loaded
4321 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4322 #ifndef PRODUCT
4323 if (PrintOpto && Verbose) {
4324 tty->print("meet of unloaded classes resulted in: ");
4325 unloaded_meet->dump();
4326 tty->cr();
4327 tty->print(" this == ");
4328 dump();
4329 tty->cr();
4330 tty->print(" tinst == ");
4331 tinst->dump();
4332 tty->cr();
4333 }
4334 #endif
4335 res = unloaded_meet;
4336 } else {
4337 if (kind == NOT_SUBTYPE && instance_id > 0) {
4338 instance_id = InstanceBot;
4339 } else if (kind == LCA) {
4340 instance_id = InstanceBot;
4341 }
4342 ciObject* o = nullptr; // Assume not constant when done
4343 ciObject* this_oop = const_oop();
4344 ciObject* tinst_oop = tinst->const_oop();
4345 if (ptr == Constant) {
4346 if (this_oop != nullptr && tinst_oop != nullptr &&
4347 this_oop->equals(tinst_oop))
4348 o = this_oop;
4349 else if (above_centerline(_ptr)) {
4350 assert(!tinst_klass->is_interface(), "");
4351 o = tinst_oop;
4352 } else if (above_centerline(tinst->_ptr)) {
4353 assert(!this_klass->is_interface(), "");
4354 o = this_oop;
4355 } else
4356 ptr = NotNull;
4357 }
4358 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4359 }
4360
4361 return res;
4362
4363 } // End of case InstPtr
4364
4365 } // End of switch
4366 return this; // Return the double constant
4367 }
4368
4369 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4370 ciKlass*& res_klass, bool& res_xk) {
4371 ciKlass* this_klass = this_type->klass();
4372 ciKlass* other_klass = other_type->klass();
4373 bool this_xk = this_type->klass_is_exact();
4374 bool other_xk = other_type->klass_is_exact();
4375 PTR this_ptr = this_type->ptr();
4376 PTR other_ptr = other_type->ptr();
4377 const TypeInterfaces* this_interfaces = this_type->interfaces();
4378 const TypeInterfaces* other_interfaces = other_type->interfaces();
4379 // Check for easy case; klasses are equal (and perhaps not loaded!)
4380 // If we have constants, then we created oops so classes are loaded
4381 // and we can handle the constants further down. This case handles
4382 // both-not-loaded or both-loaded classes
4383 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4384 res_klass = this_klass;
4385 res_xk = this_xk;
4386 return QUICK;
4387 }
4388
4389 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4390 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4391 return UNLOADED;
4392 }
4393
4394 // !!! Here's how the symmetry requirement breaks down into invariants:
4395 // If we split one up & one down AND they subtype, take the down man.
4396 // If we split one up & one down AND they do NOT subtype, "fall hard".
4397 // If both are up and they subtype, take the subtype class.
4398 // If both are up and they do NOT subtype, "fall hard".
4399 // If both are down and they subtype, take the supertype class.
4400 // If both are down and they do NOT subtype, "fall hard".
4401 // Constants treated as down.
4402
4403 // Now, reorder the above list; observe that both-down+subtype is also
4404 // "fall hard"; "fall hard" becomes the default case:
4405 // If we split one up & one down AND they subtype, take the down man.
4406 // If both are up and they subtype, take the subtype class.
4407
4408 // If both are down and they subtype, "fall hard".
4409 // If both are down and they do NOT subtype, "fall hard".
4410 // If both are up and they do NOT subtype, "fall hard".
4411 // If we split one up & one down AND they do NOT subtype, "fall hard".
4412
4413 // If a proper subtype is exact, and we return it, we return it exactly.
4414 // If a proper supertype is exact, there can be no subtyping relationship!
4415 // If both types are equal to the subtype, exactness is and-ed below the
4416 // centerline and or-ed above it. (N.B. Constants are always exact.)
4417
4418 // Check for subtyping:
4419 const T* subtype = nullptr;
4420 bool subtype_exact = false;
4421 if (this_type->is_same_java_type_as(other_type)) {
4422 subtype = this_type;
4423 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4424 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4425 subtype = this_type; // Pick subtyping class
4426 subtype_exact = this_xk;
4427 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4428 subtype = other_type; // Pick subtyping class
4429 subtype_exact = other_xk;
4430 }
4431
4432 if (subtype) {
4433 if (above_centerline(ptr)) { // both are up?
4434 this_type = other_type = subtype;
4435 this_xk = other_xk = subtype_exact;
4436 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4437 this_type = other_type; // tinst is down; keep down man
4438 this_xk = other_xk;
4439 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4440 other_type = this_type; // this is down; keep down man
4441 other_xk = this_xk;
4442 } else {
4443 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4444 }
4445 }
4446
4447 // Check for classes now being equal
4448 if (this_type->is_same_java_type_as(other_type)) {
4449 // If the klasses are equal, the constants may still differ. Fall to
4450 // NotNull if they do (neither constant is null; that is a special case
4451 // handled elsewhere).
4452 res_klass = this_type->klass();
4453 res_xk = this_xk;
4454 return SUBTYPE;
4455 } // Else classes are not equal
4456
4457 // Since klasses are different, we require a LCA in the Java
4458 // class hierarchy - which means we have to fall to at least NotNull.
4459 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4460 ptr = NotNull;
4461 }
4462
4463 interfaces = this_interfaces->intersection_with(other_interfaces);
4464
4465 // Now we find the LCA of Java classes
4466 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4467
4468 res_klass = k;
4469 res_xk = false;
4470
4471 return LCA;
4472 }
4473
4474 //------------------------java_mirror_type--------------------------------------
4475 ciType* TypeInstPtr::java_mirror_type() const {
4476 // must be a singleton type
4477 if( const_oop() == nullptr ) return nullptr;
4478
4479 // must be of type java.lang.Class
4480 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4481
4482 return const_oop()->as_instance()->java_mirror_type();
4483 }
4484
4485
4486 //------------------------------xdual------------------------------------------
4487 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4488 // inheritance mechanism.
4489 const Type *TypeInstPtr::xdual() const {
4490 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4491 }
4492
4493 //------------------------------eq---------------------------------------------
4494 // Structural equality check for Type representations
4495 bool TypeInstPtr::eq( const Type *t ) const {
4496 const TypeInstPtr *p = t->is_instptr();
4497 return
4498 klass()->equals(p->klass()) &&
4499 _interfaces->eq(p->_interfaces) &&
4500 TypeOopPtr::eq(p); // Check sub-type stuff
4501 }
4502
4503 //------------------------------hash-------------------------------------------
4504 // Type-specific hashing function.
4505 uint TypeInstPtr::hash(void) const {
4506 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4507 }
4508
4509 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4510 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4511 }
4512
4513
4514 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4515 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4516 }
4517
4518 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4519 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4520 }
4521
4522
4523 //------------------------------dump2------------------------------------------
4524 // Dump oop Type
4525 #ifndef PRODUCT
4526 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4540 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4541 char* buf = ss.as_string(/* c_heap= */false);
4542 StringUtils::replace_no_expand(buf, "\n", "");
4543 st->print_raw(buf);
4544 }
4545 case BotPTR:
4546 if (!WizardMode && !Verbose) {
4547 if( _klass_is_exact ) st->print(":exact");
4548 break;
4549 }
4550 case TopPTR:
4551 case AnyNull:
4552 case NotNull:
4553 st->print(":%s", ptr_msg[_ptr]);
4554 if( _klass_is_exact ) st->print(":exact");
4555 break;
4556 default:
4557 break;
4558 }
4559
4560 if( _offset ) { // Dump offset, if any
4561 if( _offset == OffsetBot ) st->print("+any");
4562 else if( _offset == OffsetTop ) st->print("+unknown");
4563 else st->print("+%d", _offset);
4564 }
4565
4566 st->print(" *");
4567 if (_instance_id == InstanceTop)
4568 st->print(",iid=top");
4569 else if (_instance_id != InstanceBot)
4570 st->print(",iid=%d",_instance_id);
4571
4572 dump_inline_depth(st);
4573 dump_speculative(st);
4574 }
4575 #endif
4576
4577 //------------------------------add_offset-------------------------------------
4578 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4579 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4580 _instance_id, add_offset_speculative(offset), _inline_depth);
4581 }
4582
4583 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4584 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4585 _instance_id, with_offset_speculative(offset), _inline_depth);
4586 }
4587
4588 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4589 if (_speculative == nullptr) {
4590 return this;
4591 }
4592 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4593 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4594 _instance_id, nullptr, _inline_depth);
4595 }
4596
4597 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4598 if (!UseInlineDepthForSpeculativeTypes) {
4599 return this;
4600 }
4601 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4602 }
4603
4604 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4605 assert(is_known_instance(), "should be known");
4606 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4607 }
4608
4609 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4610 bool xk = klass_is_exact();
4611 ciInstanceKlass* ik = klass()->as_instance_klass();
4612 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4613 if (_interfaces->eq(ik)) {
4614 Compile* C = Compile::current();
4615 Dependencies* deps = C->dependencies();
4616 deps->assert_leaf_type(ik);
4617 xk = true;
4618 }
4619 }
4620 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4621 }
4622
4623 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) {
4624 static_assert(std::is_base_of<T2, T1>::value, "");
4625
4626 if (!this_one->is_instance_type(other)) {
4627 return false;
4628 }
4629
4630 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4631 return true;
4632 }
4633
4634 return this_one->klass()->is_subtype_of(other->klass()) &&
4635 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4636 }
4637
4638
4639 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4640 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4645 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4646 return true;
4647 }
4648
4649 if (this_one->is_instance_type(other)) {
4650 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4651 }
4652
4653 int dummy;
4654 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4655 if (this_top_or_bottom) {
4656 return false;
4657 }
4658
4659 const T1* other_ary = this_one->is_array_type(other);
4660 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4661 const TypePtr* this_elem = this_one->elem()->make_ptr();
4662 if (other_elem != nullptr && this_elem != nullptr) {
4663 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4664 }
4665
4666 if (other_elem == nullptr && this_elem == nullptr) {
4667 return this_one->_klass->is_subtype_of(other->_klass);
4668 }
4669
4670 return false;
4671 }
4672
4673 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4674 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4675 }
4676
4677 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4678 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4679 }
4680
4681 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4682 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4683 }
4684
4685 //=============================================================================
4686 // Convenience common pre-built types.
4687 const TypeAryPtr *TypeAryPtr::RANGE;
4688 const TypeAryPtr *TypeAryPtr::OOPS;
4689 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4690 const TypeAryPtr *TypeAryPtr::BYTES;
4691 const TypeAryPtr *TypeAryPtr::SHORTS;
4692 const TypeAryPtr *TypeAryPtr::CHARS;
4693 const TypeAryPtr *TypeAryPtr::INTS;
4694 const TypeAryPtr *TypeAryPtr::LONGS;
4695 const TypeAryPtr *TypeAryPtr::FLOATS;
4696 const TypeAryPtr *TypeAryPtr::DOUBLES;
4697
4698 //------------------------------make-------------------------------------------
4699 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4700 int instance_id, const TypePtr* speculative, int inline_depth) {
4701 assert(!(k == nullptr && ary->_elem->isa_int()),
4702 "integral arrays must be pre-equipped with a class");
4703 if (!xk) xk = ary->ary_must_be_exact();
4704 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4705 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4706 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4707 k = nullptr;
4708 }
4709 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4710 }
4711
4712 //------------------------------make-------------------------------------------
4713 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4714 int instance_id, const TypePtr* speculative, int inline_depth,
4715 bool is_autobox_cache) {
4716 assert(!(k == nullptr && ary->_elem->isa_int()),
4717 "integral arrays must be pre-equipped with a class");
4718 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4719 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4720 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4721 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4722 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4723 k = nullptr;
4724 }
4725 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4726 }
4727
4728 //------------------------------cast_to_ptr_type-------------------------------
4729 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4730 if( ptr == _ptr ) return this;
4731 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4732 }
4733
4734
4735 //-----------------------------cast_to_exactness-------------------------------
4736 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4737 if( klass_is_exact == _klass_is_exact ) return this;
4738 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4739 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4740 }
4741
4742 //-----------------------------cast_to_instance_id----------------------------
4743 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4744 if( instance_id == _instance_id ) return this;
4745 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4746 }
4747
4748
4749 //-----------------------------max_array_length-------------------------------
4750 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4751 jint TypeAryPtr::max_array_length(BasicType etype) {
4752 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4753 if (etype == T_NARROWOOP) {
4754 etype = T_OBJECT;
4755 } else if (etype == T_ILLEGAL) { // bottom[]
4756 etype = T_BYTE; // will produce conservatively high value
4757 } else {
4758 fatal("not an element type: %s", type2name(etype));
4759 }
4760 }
4761 return arrayOopDesc::max_array_length(etype);
4762 }
4763
4764 //-----------------------------narrow_size_type-------------------------------
4765 // Narrow the given size type to the index range for the given array base type.
4781 if (hi > max_hi) {
4782 hi = max_hi;
4783 if (size->is_con()) {
4784 lo = hi;
4785 }
4786 chg = true;
4787 }
4788 // Negative length arrays will produce weird intermediate dead fast-path code
4789 if (lo > hi)
4790 return TypeInt::ZERO;
4791 if (!chg)
4792 return size;
4793 return TypeInt::make(lo, hi, Type::WidenMin);
4794 }
4795
4796 //-------------------------------cast_to_size----------------------------------
4797 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4798 assert(new_size != nullptr, "");
4799 new_size = narrow_size_type(new_size);
4800 if (new_size == size()) return this;
4801 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4802 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4803 }
4804
4805 //------------------------------cast_to_stable---------------------------------
4806 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4807 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4808 return this;
4809
4810 const Type* elem = this->elem();
4811 const TypePtr* elem_ptr = elem->make_ptr();
4812
4813 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4814 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4815 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4816 }
4817
4818 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4819
4820 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4821 }
4822
4823 //-----------------------------stable_dimension--------------------------------
4824 int TypeAryPtr::stable_dimension() const {
4825 if (!is_stable()) return 0;
4826 int dim = 1;
4827 const TypePtr* elem_ptr = elem()->make_ptr();
4828 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4829 dim += elem_ptr->is_aryptr()->stable_dimension();
4830 return dim;
4831 }
4832
4833 //----------------------cast_to_autobox_cache-----------------------------------
4834 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4835 if (is_autobox_cache()) return this;
4836 const TypeOopPtr* etype = elem()->make_oopptr();
4837 if (etype == nullptr) return this;
4838 // The pointers in the autobox arrays are always non-null.
4839 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4840 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4841 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4842 }
4843
4844 //------------------------------eq---------------------------------------------
4845 // Structural equality check for Type representations
4846 bool TypeAryPtr::eq( const Type *t ) const {
4847 const TypeAryPtr *p = t->is_aryptr();
4848 return
4849 _ary == p->_ary && // Check array
4850 TypeOopPtr::eq(p); // Check sub-parts
4851 }
4852
4853 //------------------------------hash-------------------------------------------
4854 // Type-specific hashing function.
4855 uint TypeAryPtr::hash(void) const {
4856 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4857 }
4858
4859 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4860 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4861 }
4862
4863 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4864 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4865 }
4866
4867 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4868 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4869 }
4870 //------------------------------meet-------------------------------------------
4871 // Compute the MEET of two types. It returns a new Type object.
4872 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4873 // Perform a fast test for common case; meeting the same types together.
4874 if( this == t ) return this; // Meeting same type-rep?
4875 // Current "this->_base" is Pointer
4876 switch (t->base()) { // switch on original type
4880 case Long:
4881 case FloatTop:
4882 case FloatCon:
4883 case FloatBot:
4884 case DoubleTop:
4885 case DoubleCon:
4886 case DoubleBot:
4887 case NarrowOop:
4888 case NarrowKlass:
4889 case Bottom: // Ye Olde Default
4890 return Type::BOTTOM;
4891 case Top:
4892 return this;
4893
4894 default: // All else is a mistake
4895 typerr(t);
4896
4897 case OopPtr: { // Meeting to OopPtrs
4898 // Found a OopPtr type vs self-AryPtr type
4899 const TypeOopPtr *tp = t->is_oopptr();
4900 int offset = meet_offset(tp->offset());
4901 PTR ptr = meet_ptr(tp->ptr());
4902 int depth = meet_inline_depth(tp->inline_depth());
4903 const TypePtr* speculative = xmeet_speculative(tp);
4904 switch (tp->ptr()) {
4905 case TopPTR:
4906 case AnyNull: {
4907 int instance_id = meet_instance_id(InstanceTop);
4908 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4909 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4910 }
4911 case BotPTR:
4912 case NotNull: {
4913 int instance_id = meet_instance_id(tp->instance_id());
4914 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4915 }
4916 default: ShouldNotReachHere();
4917 }
4918 }
4919
4920 case AnyPtr: { // Meeting two AnyPtrs
4921 // Found an AnyPtr type vs self-AryPtr type
4922 const TypePtr *tp = t->is_ptr();
4923 int offset = meet_offset(tp->offset());
4924 PTR ptr = meet_ptr(tp->ptr());
4925 const TypePtr* speculative = xmeet_speculative(tp);
4926 int depth = meet_inline_depth(tp->inline_depth());
4927 switch (tp->ptr()) {
4928 case TopPTR:
4929 return this;
4930 case BotPTR:
4931 case NotNull:
4932 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4933 case Null:
4934 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4935 // else fall through to AnyNull
4936 case AnyNull: {
4937 int instance_id = meet_instance_id(InstanceTop);
4938 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4939 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4940 }
4941 default: ShouldNotReachHere();
4942 }
4943 }
4944
4945 case MetadataPtr:
4946 case KlassPtr:
4947 case InstKlassPtr:
4948 case AryKlassPtr:
4949 case RawPtr: return TypePtr::BOTTOM;
4950
4951 case AryPtr: { // Meeting 2 references?
4952 const TypeAryPtr *tap = t->is_aryptr();
4953 int off = meet_offset(tap->offset());
4954 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4955 PTR ptr = meet_ptr(tap->ptr());
4956 int instance_id = meet_instance_id(tap->instance_id());
4957 const TypePtr* speculative = xmeet_speculative(tap);
4958 int depth = meet_inline_depth(tap->inline_depth());
4959
4960 ciKlass* res_klass = nullptr;
4961 bool res_xk = false;
4962 const Type* elem = tary->_elem;
4963 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4964 instance_id = InstanceBot;
4965 }
4966
4967 ciObject* o = nullptr; // Assume not constant when done
4968 ciObject* this_oop = const_oop();
4969 ciObject* tap_oop = tap->const_oop();
4970 if (ptr == Constant) {
4971 if (this_oop != nullptr && tap_oop != nullptr &&
4972 this_oop->equals(tap_oop)) {
4973 o = tap_oop;
4974 } else if (above_centerline(_ptr)) {
4975 o = tap_oop;
4976 } else if (above_centerline(tap->_ptr)) {
4977 o = this_oop;
4978 } else {
4979 ptr = NotNull;
4980 }
4981 }
4982 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4983 }
4984
4985 // All arrays inherit from Object class
4986 case InstPtr: {
4987 const TypeInstPtr *tp = t->is_instptr();
4988 int offset = meet_offset(tp->offset());
4989 PTR ptr = meet_ptr(tp->ptr());
4990 int instance_id = meet_instance_id(tp->instance_id());
4991 const TypePtr* speculative = xmeet_speculative(tp);
4992 int depth = meet_inline_depth(tp->inline_depth());
4993 const TypeInterfaces* interfaces = meet_interfaces(tp);
4994 const TypeInterfaces* tp_interfaces = tp->_interfaces;
4995 const TypeInterfaces* this_interfaces = _interfaces;
4996
4997 switch (ptr) {
4998 case TopPTR:
4999 case AnyNull: // Fall 'down' to dual of object klass
5000 // For instances when a subclass meets a superclass we fall
5001 // below the centerline when the superclass is exact. We need to
5002 // do the same here.
5003 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5004 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5005 } else {
5006 // cannot subclass, so the meet has to fall badly below the centerline
5007 ptr = NotNull;
5008 instance_id = InstanceBot;
5009 interfaces = this_interfaces->intersection_with(tp_interfaces);
5010 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5011 }
5012 case Constant:
5013 case NotNull:
5014 case BotPTR: // Fall down to object klass
5015 // LCA is object_klass, but if we subclass from the top we can do better
5016 if (above_centerline(tp->ptr())) {
5017 // If 'tp' is above the centerline and it is Object class
5018 // then we can subclass in the Java class hierarchy.
5019 // For instances when a subclass meets a superclass we fall
5020 // below the centerline when the superclass is exact. We need
5021 // to do the same here.
5022 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5023 // that is, my array type is a subtype of 'tp' klass
5024 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5025 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5026 }
5027 }
5028 // The other case cannot happen, since t cannot be a subtype of an array.
5029 // The meet falls down to Object class below centerline.
5030 if (ptr == Constant) {
5031 ptr = NotNull;
5032 }
5033 if (instance_id > 0) {
5034 instance_id = InstanceBot;
5035 }
5036 interfaces = this_interfaces->intersection_with(tp_interfaces);
5037 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5038 default: typerr(t);
5039 }
5040 }
5041 }
5042 return this; // Lint noise
5043 }
5044
5045
5046 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5047 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5048 int dummy;
5049 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5050 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5051 ciKlass* this_klass = this_ary->klass();
5052 ciKlass* other_klass = other_ary->klass();
5053 bool this_xk = this_ary->klass_is_exact();
5054 bool other_xk = other_ary->klass_is_exact();
5055 PTR this_ptr = this_ary->ptr();
5056 PTR other_ptr = other_ary->ptr();
5057 res_klass = nullptr;
5058 MeetResult result = SUBTYPE;
5059 if (elem->isa_int()) {
5060 // Integral array element types have irrelevant lattice relations.
5061 // It is the klass that determines array layout, not the element type.
5062 if (this_top_or_bottom)
5063 res_klass = other_klass;
5064 else if (other_top_or_bottom || other_klass == this_klass) {
5065 res_klass = this_klass;
5066 } else {
5067 // Something like byte[int+] meets char[int+].
5068 // This must fall to bottom, not (int[-128..65535])[int+].
5069 // instance_id = InstanceBot;
5070 elem = Type::BOTTOM;
5071 result = NOT_SUBTYPE;
5072 if (above_centerline(ptr) || ptr == Constant) {
5073 ptr = NotNull;
5074 res_xk = false;
5075 return NOT_SUBTYPE;
5076 }
5077 }
5078 } else {// Non integral arrays.
5079 // Must fall to bottom if exact klasses in upper lattice
5080 // are not equal or super klass is exact.
5081 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5082 // meet with top[] and bottom[] are processed further down:
5083 !this_top_or_bottom && !other_top_or_bottom &&
5084 // both are exact and not equal:
5086 // 'tap' is exact and super or unrelated:
5087 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5088 // 'this' is exact and super or unrelated:
5089 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5090 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5091 elem = Type::BOTTOM;
5092 }
5093 ptr = NotNull;
5094 res_xk = false;
5095 return NOT_SUBTYPE;
5096 }
5097 }
5098
5099 res_xk = false;
5100 switch (other_ptr) {
5101 case AnyNull:
5102 case TopPTR:
5103 // Compute new klass on demand, do not use tap->_klass
5104 if (below_centerline(this_ptr)) {
5105 res_xk = this_xk;
5106 } else {
5107 res_xk = (other_xk || this_xk);
5108 }
5109 return result;
5110 case Constant: {
5111 if (this_ptr == Constant) {
5112 res_xk = true;
5113 } else if(above_centerline(this_ptr)) {
5114 res_xk = true;
5115 } else {
5116 // Only precise for identical arrays
5117 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5118 }
5119 return result;
5120 }
5121 case NotNull:
5122 case BotPTR:
5123 // Compute new klass on demand, do not use tap->_klass
5124 if (above_centerline(this_ptr)) {
5125 res_xk = other_xk;
5126 } else {
5127 res_xk = (other_xk && this_xk) &&
5128 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5129 }
5130 return result;
5131 default: {
5132 ShouldNotReachHere();
5133 return result;
5134 }
5135 }
5136 return result;
5137 }
5138
5139
5140 //------------------------------xdual------------------------------------------
5141 // Dual: compute field-by-field dual
5142 const Type *TypeAryPtr::xdual() const {
5143 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());
5144 }
5145
5146 //------------------------------dump2------------------------------------------
5147 #ifndef PRODUCT
5148 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5149 _ary->dump2(d,depth,st);
5150 _interfaces->dump(st);
5151
5152 switch( _ptr ) {
5153 case Constant:
5154 const_oop()->print(st);
5155 break;
5156 case BotPTR:
5157 if (!WizardMode && !Verbose) {
5158 if( _klass_is_exact ) st->print(":exact");
5159 break;
5160 }
5161 case TopPTR:
5162 case AnyNull:
5163 case NotNull:
5164 st->print(":%s", ptr_msg[_ptr]);
5165 if( _klass_is_exact ) st->print(":exact");
5166 break;
5167 default:
5168 break;
5169 }
5170
5171 if( _offset != 0 ) {
5172 int header_size = objArrayOopDesc::header_size() * wordSize;
5173 if( _offset == OffsetTop ) st->print("+undefined");
5174 else if( _offset == OffsetBot ) st->print("+any");
5175 else if( _offset < header_size ) st->print("+%d", _offset);
5176 else {
5177 BasicType basic_elem_type = elem()->basic_type();
5178 if (basic_elem_type == T_ILLEGAL) {
5179 st->print("+any");
5180 } else {
5181 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5182 int elem_size = type2aelembytes(basic_elem_type);
5183 st->print("[%d]", (_offset - array_base)/elem_size);
5184 }
5185 }
5186 }
5187 st->print(" *");
5188 if (_instance_id == InstanceTop)
5189 st->print(",iid=top");
5190 else if (_instance_id != InstanceBot)
5191 st->print(",iid=%d",_instance_id);
5192
5193 dump_inline_depth(st);
5194 dump_speculative(st);
5195 }
5196 #endif
5197
5198 bool TypeAryPtr::empty(void) const {
5199 if (_ary->empty()) return true;
5200 return TypeOopPtr::empty();
5201 }
5202
5203 //------------------------------add_offset-------------------------------------
5204 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5205 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5206 }
5207
5208 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5209 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5210 }
5211
5212 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5213 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5214 }
5215
5216 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5217 if (_speculative == nullptr) {
5218 return this;
5219 }
5220 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5221 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5222 }
5223
5224 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5225 if (!UseInlineDepthForSpeculativeTypes) {
5226 return this;
5227 }
5228 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5229 }
5230
5231 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5232 assert(is_known_instance(), "should be known");
5233 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5234 }
5235
5236 //=============================================================================
5237
5238 //------------------------------hash-------------------------------------------
5239 // Type-specific hashing function.
5240 uint TypeNarrowPtr::hash(void) const {
5241 return _ptrtype->hash() + 7;
5242 }
5243
5244 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5245 return _ptrtype->singleton();
5246 }
5247
5248 bool TypeNarrowPtr::empty(void) const {
5249 return _ptrtype->empty();
5250 }
5251
5252 intptr_t TypeNarrowPtr::get_con() const {
5253 return _ptrtype->get_con();
5254 }
5255
5256 bool TypeNarrowPtr::eq( const Type *t ) const {
5257 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5308
5309 case Int: // Mixing ints & oops happens when javac
5310 case Long: // reuses local variables
5311 case FloatTop:
5312 case FloatCon:
5313 case FloatBot:
5314 case DoubleTop:
5315 case DoubleCon:
5316 case DoubleBot:
5317 case AnyPtr:
5318 case RawPtr:
5319 case OopPtr:
5320 case InstPtr:
5321 case AryPtr:
5322 case MetadataPtr:
5323 case KlassPtr:
5324 case InstKlassPtr:
5325 case AryKlassPtr:
5326 case NarrowOop:
5327 case NarrowKlass:
5328
5329 case Bottom: // Ye Olde Default
5330 return Type::BOTTOM;
5331 case Top:
5332 return this;
5333
5334 default: // All else is a mistake
5335 typerr(t);
5336
5337 } // End of switch
5338
5339 return this;
5340 }
5341
5342 #ifndef PRODUCT
5343 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5344 _ptrtype->dump2(d, depth, st);
5345 }
5346 #endif
5347
5348 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5392 return (one == two) && TypePtr::eq(t);
5393 } else {
5394 return one->equals(two) && TypePtr::eq(t);
5395 }
5396 }
5397
5398 //------------------------------hash-------------------------------------------
5399 // Type-specific hashing function.
5400 uint TypeMetadataPtr::hash(void) const {
5401 return
5402 (metadata() ? metadata()->hash() : 0) +
5403 TypePtr::hash();
5404 }
5405
5406 //------------------------------singleton--------------------------------------
5407 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5408 // constants
5409 bool TypeMetadataPtr::singleton(void) const {
5410 // detune optimizer to not generate constant metadata + constant offset as a constant!
5411 // TopPTR, Null, AnyNull, Constant are all singletons
5412 return (_offset == 0) && !below_centerline(_ptr);
5413 }
5414
5415 //------------------------------add_offset-------------------------------------
5416 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5417 return make( _ptr, _metadata, xadd_offset(offset));
5418 }
5419
5420 //-----------------------------filter------------------------------------------
5421 // Do not allow interface-vs.-noninterface joins to collapse to top.
5422 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5423 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5424 if (ft == nullptr || ft->empty())
5425 return Type::TOP; // Canonical empty value
5426 return ft;
5427 }
5428
5429 //------------------------------get_con----------------------------------------
5430 intptr_t TypeMetadataPtr::get_con() const {
5431 assert( _ptr == Null || _ptr == Constant, "" );
5432 assert( _offset >= 0, "" );
5433
5434 if (_offset != 0) {
5435 // After being ported to the compiler interface, the compiler no longer
5436 // directly manipulates the addresses of oops. Rather, it only has a pointer
5437 // to a handle at compile time. This handle is embedded in the generated
5438 // code and dereferenced at the time the nmethod is made. Until that time,
5439 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5440 // have access to the addresses!). This does not seem to currently happen,
5441 // but this assertion here is to help prevent its occurrence.
5442 tty->print_cr("Found oop constant with non-zero offset");
5443 ShouldNotReachHere();
5444 }
5445
5446 return (intptr_t)metadata()->constant_encoding();
5447 }
5448
5449 //------------------------------cast_to_ptr_type-------------------------------
5450 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5451 if( ptr == _ptr ) return this;
5452 return make(ptr, metadata(), _offset);
5453 }
5454
5465 case Long: // reuses local variables
5466 case FloatTop:
5467 case FloatCon:
5468 case FloatBot:
5469 case DoubleTop:
5470 case DoubleCon:
5471 case DoubleBot:
5472 case NarrowOop:
5473 case NarrowKlass:
5474 case Bottom: // Ye Olde Default
5475 return Type::BOTTOM;
5476 case Top:
5477 return this;
5478
5479 default: // All else is a mistake
5480 typerr(t);
5481
5482 case AnyPtr: {
5483 // Found an AnyPtr type vs self-OopPtr type
5484 const TypePtr *tp = t->is_ptr();
5485 int offset = meet_offset(tp->offset());
5486 PTR ptr = meet_ptr(tp->ptr());
5487 switch (tp->ptr()) {
5488 case Null:
5489 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5490 // else fall through:
5491 case TopPTR:
5492 case AnyNull: {
5493 return make(ptr, _metadata, offset);
5494 }
5495 case BotPTR:
5496 case NotNull:
5497 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5498 default: typerr(t);
5499 }
5500 }
5501
5502 case RawPtr:
5503 case KlassPtr:
5504 case InstKlassPtr:
5505 case AryKlassPtr:
5506 case OopPtr:
5507 case InstPtr:
5508 case AryPtr:
5509 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5510
5511 case MetadataPtr: {
5512 const TypeMetadataPtr *tp = t->is_metadataptr();
5513 int offset = meet_offset(tp->offset());
5514 PTR tptr = tp->ptr();
5515 PTR ptr = meet_ptr(tptr);
5516 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5517 if (tptr == TopPTR || _ptr == TopPTR ||
5518 metadata()->equals(tp->metadata())) {
5519 return make(ptr, md, offset);
5520 }
5521 // metadata is different
5522 if( ptr == Constant ) { // Cannot be equal constants, so...
5523 if( tptr == Constant && _ptr != Constant) return t;
5524 if( _ptr == Constant && tptr != Constant) return this;
5525 ptr = NotNull; // Fall down in lattice
5526 }
5527 return make(ptr, nullptr, offset);
5528 break;
5529 }
5530 } // End of switch
5531 return this; // Return the double constant
5532 }
5533
5534
5535 //------------------------------xdual------------------------------------------
5536 // Dual of a pure metadata pointer.
5537 const Type *TypeMetadataPtr::xdual() const {
5538 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5539 }
5540
5541 //------------------------------dump2------------------------------------------
5542 #ifndef PRODUCT
5543 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5544 st->print("metadataptr:%s", ptr_msg[_ptr]);
5545 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5546 switch( _offset ) {
5547 case OffsetTop: st->print("+top"); break;
5548 case OffsetBot: st->print("+any"); break;
5549 case 0: break;
5550 default: st->print("+%d",_offset); break;
5551 }
5552 }
5553 #endif
5554
5555
5556 //=============================================================================
5557 // Convenience common pre-built type.
5558 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5559
5560 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5561 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5562 }
5563
5564 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5565 return make(Constant, m, 0);
5566 }
5567 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5568 return make(Constant, m, 0);
5569 }
5570
5571 //------------------------------make-------------------------------------------
5572 // Create a meta data constant
5573 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5574 assert(m == nullptr || !m->is_klass(), "wrong type");
5575 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5576 }
5577
5578
5579 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5580 const Type* elem = _ary->_elem;
5581 bool xk = klass_is_exact();
5582 if (elem->make_oopptr() != nullptr) {
5583 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5584 if (elem->is_klassptr()->klass_is_exact()) {
5585 xk = true;
5586 }
5587 }
5588 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5589 }
5590
5591 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5592 if (klass->is_instance_klass()) {
5593 return TypeInstKlassPtr::make(klass, interface_handling);
5594 }
5595 return TypeAryKlassPtr::make(klass, interface_handling);
5596 }
5597
5598 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5599 if (klass->is_instance_klass()) {
5600 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5601 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5602 }
5603 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5604 }
5605
5606
5607 //------------------------------TypeKlassPtr-----------------------------------
5608 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5609 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5610 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5611 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5612 }
5613
5614 // Is there a single ciKlass* that can represent that type?
5615 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5616 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5617 if (_interfaces->empty()) {
5618 return _klass;
5619 }
5620 if (_klass != ciEnv::current()->Object_klass()) {
5621 if (_interfaces->eq(_klass->as_instance_klass())) {
5622 return _klass;
5623 }
5624 return nullptr;
5625 }
5626 return _interfaces->exact_klass();
5627 }
5628
5629 //------------------------------eq---------------------------------------------
5630 // Structural equality check for Type representations
5631 bool TypeKlassPtr::eq(const Type *t) const {
5632 const TypeKlassPtr *p = t->is_klassptr();
5633 return
5634 _interfaces->eq(p->_interfaces) &&
5635 TypePtr::eq(p);
5636 }
5637
5638 //------------------------------hash-------------------------------------------
5639 // Type-specific hashing function.
5640 uint TypeKlassPtr::hash(void) const {
5641 return TypePtr::hash() + _interfaces->hash();
5642 }
5643
5644 //------------------------------singleton--------------------------------------
5645 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5646 // constants
5647 bool TypeKlassPtr::singleton(void) const {
5648 // detune optimizer to not generate constant klass + constant offset as a constant!
5649 // TopPTR, Null, AnyNull, Constant are all singletons
5650 return (_offset == 0) && !below_centerline(_ptr);
5651 }
5652
5653 // Do not allow interface-vs.-noninterface joins to collapse to top.
5654 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5655 // logic here mirrors the one from TypeOopPtr::filter. See comments
5656 // there.
5657 const Type* ft = join_helper(kills, include_speculative);
5658 const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5659 const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5660
5661 if (ft->empty()) {
5662 return Type::TOP; // Canonical empty value
5663 }
5664
5665 return ft;
5666 }
5667
5668 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5669 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5670 return _interfaces->union_with(other->_interfaces);
5671 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5672 return other->_interfaces;
5673 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5674 return _interfaces;
5675 }
5676 return _interfaces->intersection_with(other->_interfaces);
5677 }
5678
5679 //------------------------------get_con----------------------------------------
5680 intptr_t TypeKlassPtr::get_con() const {
5681 assert( _ptr == Null || _ptr == Constant, "" );
5682 assert( _offset >= 0, "" );
5683
5684 if (_offset != 0) {
5685 // After being ported to the compiler interface, the compiler no longer
5686 // directly manipulates the addresses of oops. Rather, it only has a pointer
5687 // to a handle at compile time. This handle is embedded in the generated
5688 // code and dereferenced at the time the nmethod is made. Until that time,
5689 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5690 // have access to the addresses!). This does not seem to currently happen,
5691 // but this assertion here is to help prevent its occurrence.
5692 tty->print_cr("Found oop constant with non-zero offset");
5693 ShouldNotReachHere();
5694 }
5695
5696 ciKlass* k = exact_klass();
5697
5698 return (intptr_t)k->constant_encoding();
5699 }
5700
5701 //------------------------------dump2------------------------------------------
5702 // Dump Klass Type
5703 #ifndef PRODUCT
5704 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5708 case NotNull:
5709 {
5710 const char *name = klass()->name()->as_utf8();
5711 if (name) {
5712 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5713 } else {
5714 ShouldNotReachHere();
5715 }
5716 _interfaces->dump(st);
5717 }
5718 case BotPTR:
5719 if (!WizardMode && !Verbose && _ptr != Constant) break;
5720 case TopPTR:
5721 case AnyNull:
5722 st->print(":%s", ptr_msg[_ptr]);
5723 if (_ptr == Constant) st->print(":exact");
5724 break;
5725 default:
5726 break;
5727 }
5728
5729 if (_offset) { // Dump offset, if any
5730 if (_offset == OffsetBot) { st->print("+any"); }
5731 else if (_offset == OffsetTop) { st->print("+unknown"); }
5732 else { st->print("+%d", _offset); }
5733 }
5734
5735 st->print(" *");
5736 }
5737 #endif
5738
5739 //=============================================================================
5740 // Convenience common pre-built types.
5741
5742 // Not-null object klass or below
5743 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5744 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5745
5746 bool TypeInstKlassPtr::eq(const Type *t) const {
5747 const TypeKlassPtr *p = t->is_klassptr();
5748 return
5749 klass()->equals(p->klass()) &&
5750 TypeKlassPtr::eq(p);
5751 }
5752
5753 uint TypeInstKlassPtr::hash(void) const {
5754 return klass()->hash() + TypeKlassPtr::hash();
5755 }
5756
5757 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5758 TypeInstKlassPtr *r =
5759 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5760
5761 return r;
5762 }
5763
5764 //------------------------------add_offset-------------------------------------
5765 // Access internals of klass object
5766 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5767 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5768 }
5769
5770 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5771 return make(_ptr, klass(), _interfaces, offset);
5772 }
5773
5774 //------------------------------cast_to_ptr_type-------------------------------
5775 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5776 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5777 if( ptr == _ptr ) return this;
5778 return make(ptr, _klass, _interfaces, _offset);
5779 }
5780
5781
5782 bool TypeInstKlassPtr::must_be_exact() const {
5783 if (!_klass->is_loaded()) return false;
5784 ciInstanceKlass* ik = _klass->as_instance_klass();
5785 if (ik->is_final()) return true; // cannot clear xk
5786 return false;
5787 }
5788
5789 //-----------------------------cast_to_exactness-------------------------------
5790 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5791 if (klass_is_exact == (_ptr == Constant)) return this;
5792 if (must_be_exact()) return this;
5793 ciKlass* k = klass();
5794 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5795 }
5796
5797
5798 //-----------------------------as_instance_type--------------------------------
5799 // Corresponding type for an instance of the given class.
5800 // It will be NotNull, and exact if and only if the klass type is exact.
5801 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5802 ciKlass* k = klass();
5803 bool xk = klass_is_exact();
5804 Compile* C = Compile::current();
5805 Dependencies* deps = C->dependencies();
5806 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5807 // Element is an instance
5808 bool klass_is_exact = false;
5809 const TypeInterfaces* interfaces = _interfaces;
5810 if (k->is_loaded()) {
5811 // Try to set klass_is_exact.
5812 ciInstanceKlass* ik = k->as_instance_klass();
5813 klass_is_exact = ik->is_final();
5814 if (!klass_is_exact && klass_change
5815 && deps != nullptr && UseUniqueSubclasses) {
5816 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5817 if (sub != nullptr) {
5818 if (_interfaces->eq(sub)) {
5819 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5820 k = ik = sub;
5821 xk = sub->is_final();
5822 }
5823 }
5824 }
5825 }
5826 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5827 }
5828
5829 //------------------------------xmeet------------------------------------------
5830 // Compute the MEET of two types, return a new Type object.
5831 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
5832 // Perform a fast test for common case; meeting the same types together.
5833 if( this == t ) return this; // Meeting same type-rep?
5834
5835 // Current "this->_base" is Pointer
5836 switch (t->base()) { // switch on original type
5837
5838 case Int: // Mixing ints & oops happens when javac
5839 case Long: // reuses local variables
5840 case FloatTop:
5841 case FloatCon:
5842 case FloatBot:
5843 case DoubleTop:
5844 case DoubleCon:
5845 case DoubleBot:
5846 case NarrowOop:
5847 case NarrowKlass:
5848 case Bottom: // Ye Olde Default
5849 return Type::BOTTOM;
5850 case Top:
5851 return this;
5852
5853 default: // All else is a mistake
5854 typerr(t);
5855
5856 case AnyPtr: { // Meeting to AnyPtrs
5857 // Found an AnyPtr type vs self-KlassPtr type
5858 const TypePtr *tp = t->is_ptr();
5859 int offset = meet_offset(tp->offset());
5860 PTR ptr = meet_ptr(tp->ptr());
5861 switch (tp->ptr()) {
5862 case TopPTR:
5863 return this;
5864 case Null:
5865 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5866 case AnyNull:
5867 return make( ptr, klass(), _interfaces, offset );
5868 case BotPTR:
5869 case NotNull:
5870 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5871 default: typerr(t);
5872 }
5873 }
5874
5875 case RawPtr:
5876 case MetadataPtr:
5877 case OopPtr:
5878 case AryPtr: // Meet with AryPtr
5879 case InstPtr: // Meet with InstPtr
5880 return TypePtr::BOTTOM;
5881
5882 //
5883 // A-top }
5884 // / | \ } Tops
5885 // B-top A-any C-top }
5886 // | / | \ | } Any-nulls
5887 // B-any | C-any }
5888 // | | |
5889 // B-con A-con C-con } constants; not comparable across classes
5890 // | | |
5891 // B-not | C-not }
5892 // | \ | / | } not-nulls
5893 // B-bot A-not C-bot }
5894 // \ | / } Bottoms
5895 // A-bot }
5896 //
5897
5898 case InstKlassPtr: { // Meet two KlassPtr types
5899 const TypeInstKlassPtr *tkls = t->is_instklassptr();
5900 int off = meet_offset(tkls->offset());
5901 PTR ptr = meet_ptr(tkls->ptr());
5902 const TypeInterfaces* interfaces = meet_interfaces(tkls);
5903
5904 ciKlass* res_klass = nullptr;
5905 bool res_xk = false;
5906 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5907 case UNLOADED:
5908 ShouldNotReachHere();
5909 case SUBTYPE:
5910 case NOT_SUBTYPE:
5911 case LCA:
5912 case QUICK: {
5913 assert(res_xk == (ptr == Constant), "");
5914 const Type* res = make(ptr, res_klass, interfaces, off);
5915 return res;
5916 }
5917 default:
5918 ShouldNotReachHere();
5919 }
5920 } // End of case KlassPtr
5921 case AryKlassPtr: { // All arrays inherit from Object class
5922 const TypeAryKlassPtr *tp = t->is_aryklassptr();
5923 int offset = meet_offset(tp->offset());
5924 PTR ptr = meet_ptr(tp->ptr());
5925 const TypeInterfaces* interfaces = meet_interfaces(tp);
5926 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5927 const TypeInterfaces* this_interfaces = _interfaces;
5928
5929 switch (ptr) {
5930 case TopPTR:
5931 case AnyNull: // Fall 'down' to dual of object klass
5932 // For instances when a subclass meets a superclass we fall
5933 // below the centerline when the superclass is exact. We need to
5934 // do the same here.
5935 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5936 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5937 } else {
5938 // cannot subclass, so the meet has to fall badly below the centerline
5939 ptr = NotNull;
5940 interfaces = _interfaces->intersection_with(tp->_interfaces);
5941 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5942 }
5943 case Constant:
5944 case NotNull:
5945 case BotPTR: // Fall down to object klass
5946 // LCA is object_klass, but if we subclass from the top we can do better
5947 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5948 // If 'this' (InstPtr) is above the centerline and it is Object class
5949 // then we can subclass in the Java class hierarchy.
5950 // For instances when a subclass meets a superclass we fall
5951 // below the centerline when the superclass is exact. We need
5952 // to do the same here.
5953 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5954 // that is, tp's array type is a subtype of my klass
5955 return TypeAryKlassPtr::make(ptr,
5956 tp->elem(), tp->klass(), offset);
5957 }
5958 }
5959 // The other case cannot happen, since I cannot be a subtype of an array.
5960 // The meet falls down to Object class below centerline.
5961 if( ptr == Constant )
5962 ptr = NotNull;
5963 interfaces = this_interfaces->intersection_with(tp_interfaces);
5964 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5965 default: typerr(t);
5966 }
5967 }
5968
5969 } // End of switch
5970 return this; // Return the double constant
5971 }
5972
5973 //------------------------------xdual------------------------------------------
5974 // Dual: compute field-by-field dual
5975 const Type *TypeInstKlassPtr::xdual() const {
5976 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5977 }
5978
5979 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) {
5980 static_assert(std::is_base_of<T2, T1>::value, "");
5981 if (!this_one->is_loaded() || !other->is_loaded()) {
5982 return false;
5983 }
5984 if (!this_one->is_instance_type(other)) {
5985 return false;
5986 }
5987
5988 if (!other_exact) {
5989 return false;
5990 }
5991
5992 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5993 return true;
5994 }
5995
5996 return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces->contains(other->_interfaces);
6057 const TypeInterfaces* interfaces = _interfaces;
6058 if (k->is_loaded()) {
6059 ciInstanceKlass* ik = k->as_instance_klass();
6060 bool klass_is_exact = ik->is_final();
6061 if (!klass_is_exact &&
6062 deps != nullptr) {
6063 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6064 if (sub != nullptr) {
6065 if (_interfaces->eq(sub)) {
6066 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6067 k = ik = sub;
6068 klass_is_exact = sub->is_final();
6069 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6070 }
6071 }
6072 }
6073 }
6074 return this;
6075 }
6076
6077
6078 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6079 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6080 }
6081
6082 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6083 if (k->is_obj_array_klass()) {
6084 // Element is an object array. Recursively call ourself.
6085 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6086 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6087 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6088 } else if (k->is_type_array_klass()) {
6089 // Element is an typeArray
6090 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6091 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6092 } else {
6093 ShouldNotReachHere();
6094 return nullptr;
6095 }
6096 }
6097
6098 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6099 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6100 }
6101
6102 //------------------------------eq---------------------------------------------
6103 // Structural equality check for Type representations
6104 bool TypeAryKlassPtr::eq(const Type *t) const {
6105 const TypeAryKlassPtr *p = t->is_aryklassptr();
6106 return
6107 _elem == p->_elem && // Check array
6108 TypeKlassPtr::eq(p); // Check sub-parts
6109 }
6110
6111 //------------------------------hash-------------------------------------------
6112 // Type-specific hashing function.
6113 uint TypeAryKlassPtr::hash(void) const {
6114 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6115 }
6116
6117 //----------------------compute_klass------------------------------------------
6118 // Compute the defining klass for this class
6119 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6120 // Compute _klass based on element type.
6121 ciKlass* k_ary = nullptr;
6122 const TypeInstPtr *tinst;
6123 const TypeAryPtr *tary;
6124 const Type* el = elem();
6125 if (el->isa_narrowoop()) {
6126 el = el->make_ptr();
6127 }
6128
6129 // Get element klass
6130 if ((tinst = el->isa_instptr()) != nullptr) {
6131 // Leave k_ary at null.
6132 } else if ((tary = el->isa_aryptr()) != nullptr) {
6133 // Leave k_ary at null.
6134 } else if ((el->base() == Type::Top) ||
6135 (el->base() == Type::Bottom)) {
6136 // element type of Bottom occurs from meet of basic type
6137 // and object; Top occurs when doing join on Bottom.
6138 // Leave k_ary at null.
6139 } else {
6140 // Cannot compute array klass directly from basic type,
6141 // since subtypes of TypeInt all have basic type T_INT.
6142 #ifdef ASSERT
6143 if (verify && el->isa_int()) {
6144 // Check simple cases when verifying klass.
6145 BasicType bt = T_ILLEGAL;
6146 if (el == TypeInt::BYTE) {
6147 bt = T_BYTE;
6148 } else if (el == TypeInt::SHORT) {
6149 bt = T_SHORT;
6150 } else if (el == TypeInt::CHAR) {
6151 bt = T_CHAR;
6152 } else if (el == TypeInt::INT) {
6153 bt = T_INT;
6182 // type TypeAryPtr::OOPS. This Type is shared between all
6183 // active compilations. However, the ciKlass which represents
6184 // this Type is *not* shared between compilations, so caching
6185 // this value would result in fetching a dangling pointer.
6186 //
6187 // Recomputing the underlying ciKlass for each request is
6188 // a bit less efficient than caching, but calls to
6189 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6190 ((TypeAryPtr*)this)->_klass = k_ary;
6191 }
6192 return k_ary;
6193 }
6194
6195 // Is there a single ciKlass* that can represent that type?
6196 ciKlass* TypeAryPtr::exact_klass_helper() const {
6197 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6198 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6199 if (k == nullptr) {
6200 return nullptr;
6201 }
6202 k = ciObjArrayKlass::make(k);
6203 return k;
6204 }
6205
6206 return klass();
6207 }
6208
6209 const Type* TypeAryPtr::base_element_type(int& dims) const {
6210 const Type* elem = this->elem();
6211 dims = 1;
6212 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6213 elem = elem->make_ptr()->is_aryptr()->elem();
6214 dims++;
6215 }
6216 return elem;
6217 }
6218
6219 //------------------------------add_offset-------------------------------------
6220 // Access internals of klass object
6221 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6222 return make(_ptr, elem(), klass(), xadd_offset(offset));
6223 }
6224
6225 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6226 return make(_ptr, elem(), klass(), offset);
6227 }
6228
6229 //------------------------------cast_to_ptr_type-------------------------------
6230 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6231 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6232 if (ptr == _ptr) return this;
6233 return make(ptr, elem(), _klass, _offset);
6234 }
6235
6236 bool TypeAryKlassPtr::must_be_exact() const {
6237 if (_elem == Type::BOTTOM) return false;
6238 if (_elem == Type::TOP ) return false;
6239 const TypeKlassPtr* tk = _elem->isa_klassptr();
6240 if (!tk) return true; // a primitive type, like int
6241 return tk->must_be_exact();
6242 }
6243
6244
6245 //-----------------------------cast_to_exactness-------------------------------
6246 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6247 if (must_be_exact()) return this; // cannot clear xk
6248 ciKlass* k = _klass;
6249 const Type* elem = this->elem();
6250 if (elem->isa_klassptr() && !klass_is_exact) {
6251 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6252 }
6253 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6254 }
6255
6256
6257 //-----------------------------as_instance_type--------------------------------
6258 // Corresponding type for an instance of the given class.
6259 // It will be NotNull, and exact if and only if the klass type is exact.
6260 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6261 ciKlass* k = klass();
6262 bool xk = klass_is_exact();
6263 const Type* el = nullptr;
6264 if (elem()->isa_klassptr()) {
6265 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6266 k = nullptr;
6267 } else {
6268 el = elem();
6269 }
6270 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6271 }
6272
6273
6274 //------------------------------xmeet------------------------------------------
6275 // Compute the MEET of two types, return a new Type object.
6276 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6277 // Perform a fast test for common case; meeting the same types together.
6278 if( this == t ) return this; // Meeting same type-rep?
6279
6280 // Current "this->_base" is Pointer
6281 switch (t->base()) { // switch on original type
6282
6283 case Int: // Mixing ints & oops happens when javac
6284 case Long: // reuses local variables
6285 case FloatTop:
6286 case FloatCon:
6287 case FloatBot:
6288 case DoubleTop:
6289 case DoubleCon:
6290 case DoubleBot:
6291 case NarrowOop:
6292 case NarrowKlass:
6293 case Bottom: // Ye Olde Default
6294 return Type::BOTTOM;
6295 case Top:
6296 return this;
6297
6298 default: // All else is a mistake
6299 typerr(t);
6300
6301 case AnyPtr: { // Meeting to AnyPtrs
6302 // Found an AnyPtr type vs self-KlassPtr type
6303 const TypePtr *tp = t->is_ptr();
6304 int offset = meet_offset(tp->offset());
6305 PTR ptr = meet_ptr(tp->ptr());
6306 switch (tp->ptr()) {
6307 case TopPTR:
6308 return this;
6309 case Null:
6310 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6311 case AnyNull:
6312 return make( ptr, _elem, klass(), offset );
6313 case BotPTR:
6314 case NotNull:
6315 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6316 default: typerr(t);
6317 }
6318 }
6319
6320 case RawPtr:
6321 case MetadataPtr:
6322 case OopPtr:
6323 case AryPtr: // Meet with AryPtr
6324 case InstPtr: // Meet with InstPtr
6325 return TypePtr::BOTTOM;
6326
6327 //
6328 // A-top }
6329 // / | \ } Tops
6330 // B-top A-any C-top }
6331 // | / | \ | } Any-nulls
6332 // B-any | C-any }
6333 // | | |
6334 // B-con A-con C-con } constants; not comparable across classes
6335 // | | |
6336 // B-not | C-not }
6337 // | \ | / | } not-nulls
6338 // B-bot A-not C-bot }
6339 // \ | / } Bottoms
6340 // A-bot }
6341 //
6342
6343 case AryKlassPtr: { // Meet two KlassPtr types
6344 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6345 int off = meet_offset(tap->offset());
6346 const Type* elem = _elem->meet(tap->_elem);
6347
6348 PTR ptr = meet_ptr(tap->ptr());
6349 ciKlass* res_klass = nullptr;
6350 bool res_xk = false;
6351 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6352 assert(res_xk == (ptr == Constant), "");
6353 return make(ptr, elem, res_klass, off);
6354 } // End of case KlassPtr
6355 case InstKlassPtr: {
6356 const TypeInstKlassPtr *tp = t->is_instklassptr();
6357 int offset = meet_offset(tp->offset());
6358 PTR ptr = meet_ptr(tp->ptr());
6359 const TypeInterfaces* interfaces = meet_interfaces(tp);
6360 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6361 const TypeInterfaces* this_interfaces = _interfaces;
6362
6363 switch (ptr) {
6364 case TopPTR:
6365 case AnyNull: // Fall 'down' to dual of object klass
6366 // For instances when a subclass meets a superclass we fall
6367 // below the centerline when the superclass is exact. We need to
6368 // do the same here.
6369 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6370 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6371 } else {
6372 // cannot subclass, so the meet has to fall badly below the centerline
6373 ptr = NotNull;
6374 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6375 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6376 }
6377 case Constant:
6378 case NotNull:
6379 case BotPTR: // Fall down to object klass
6380 // LCA is object_klass, but if we subclass from the top we can do better
6381 if (above_centerline(tp->ptr())) {
6382 // If 'tp' is above the centerline and it is Object class
6383 // then we can subclass in the Java class hierarchy.
6384 // For instances when a subclass meets a superclass we fall
6385 // below the centerline when the superclass is exact. We need
6386 // to do the same here.
6387 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6388 // that is, my array type is a subtype of 'tp' klass
6389 return make(ptr, _elem, _klass, offset);
6390 }
6391 }
6392 // The other case cannot happen, since t cannot be a subtype of an array.
6393 // The meet falls down to Object class below centerline.
6394 if (ptr == Constant)
6395 ptr = NotNull;
6396 interfaces = this_interfaces->intersection_with(tp_interfaces);
6397 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6398 default: typerr(t);
6399 }
6400 }
6401
6402 } // End of switch
6403 return this; // Return the double constant
6404 }
6405
6406 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) {
6407 static_assert(std::is_base_of<T2, T1>::value, "");
6408
6409 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6410 return true;
6411 }
6412
6413 int dummy;
6414 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6415
6416 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6417 return false;
6418 }
6419
6420 if (this_one->is_instance_type(other)) {
6421 return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->intersection_with(this_one->_interfaces)->eq(other->_interfaces) && other_exact;
6422 }
6423
6424 assert(this_one->is_array_type(other), "");
6425 const T1* other_ary = this_one->is_array_type(other);
6426 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6427 if (other_top_or_bottom) {
6428 return false;
6429 }
6430
6431 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6432 const TypePtr* this_elem = this_one->elem()->make_ptr();
6433 if (this_elem != nullptr && other_elem != nullptr) {
6434 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6435 }
6436 if (this_elem == nullptr && other_elem == nullptr) {
6437 return this_one->_klass->is_subtype_of(other->_klass);
6438 }
6439 return false;
6440 }
6441
6442 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6443 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6444 }
6445
6446 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6447 static_assert(std::is_base_of<T2, T1>::value, "");
6448
6449 int dummy;
6450 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6451
6452 if (!this_one->is_array_type(other) ||
6453 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6501 }
6502
6503 const TypePtr* this_elem = this_one->elem()->make_ptr();
6504 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6505 if (other_elem != nullptr && this_elem != nullptr) {
6506 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6507 }
6508 if (other_elem == nullptr && this_elem == nullptr) {
6509 return this_one->_klass->is_subtype_of(other->_klass);
6510 }
6511 return false;
6512 }
6513
6514 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6515 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6516 }
6517
6518 //------------------------------xdual------------------------------------------
6519 // Dual: compute field-by-field dual
6520 const Type *TypeAryKlassPtr::xdual() const {
6521 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6522 }
6523
6524 // Is there a single ciKlass* that can represent that type?
6525 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6526 if (elem()->isa_klassptr()) {
6527 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6528 if (k == nullptr) {
6529 return nullptr;
6530 }
6531 k = ciObjArrayKlass::make(k);
6532 return k;
6533 }
6534
6535 return klass();
6536 }
6537
6538 ciKlass* TypeAryKlassPtr::klass() const {
6539 if (_klass != nullptr) {
6540 return _klass;
6541 }
6542 ciKlass* k = nullptr;
6543 if (elem()->isa_klassptr()) {
6544 // leave null
6545 } else if ((elem()->base() == Type::Top) ||
6546 (elem()->base() == Type::Bottom)) {
6547 } else {
6548 k = ciTypeArrayKlass::make(elem()->basic_type());
6549 ((TypeAryKlassPtr*)this)->_klass = k;
6550 }
6551 return k;
6558 switch( _ptr ) {
6559 case Constant:
6560 st->print("precise ");
6561 case NotNull:
6562 {
6563 st->print("[");
6564 _elem->dump2(d, depth, st);
6565 _interfaces->dump(st);
6566 st->print(": ");
6567 }
6568 case BotPTR:
6569 if( !WizardMode && !Verbose && _ptr != Constant ) break;
6570 case TopPTR:
6571 case AnyNull:
6572 st->print(":%s", ptr_msg[_ptr]);
6573 if( _ptr == Constant ) st->print(":exact");
6574 break;
6575 default:
6576 break;
6577 }
6578
6579 if( _offset ) { // Dump offset, if any
6580 if( _offset == OffsetBot ) { st->print("+any"); }
6581 else if( _offset == OffsetTop ) { st->print("+unknown"); }
6582 else { st->print("+%d", _offset); }
6583 }
6584
6585 st->print(" *");
6586 }
6587 #endif
6588
6589 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6590 const Type* elem = this->elem();
6591 dims = 1;
6592 while (elem->isa_aryklassptr()) {
6593 elem = elem->is_aryklassptr()->elem();
6594 dims++;
6595 }
6596 return elem;
6597 }
6598
6599 //=============================================================================
6600 // Convenience common pre-built types.
6601
6602 //------------------------------make-------------------------------------------
6603 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6604 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6605 }
6606
6607 //------------------------------make-------------------------------------------
6608 const TypeFunc *TypeFunc::make(ciMethod* method) {
6609 Compile* C = Compile::current();
6610 const TypeFunc* tf = C->last_tf(method); // check cache
6611 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6612 const TypeTuple *domain;
6613 if (method->is_static()) {
6614 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6615 } else {
6616 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6617 }
6618 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6619 tf = TypeFunc::make(domain, range);
6620 C->set_last_tf(method, tf); // fill cache
6621 return tf;
6622 }
6623
6624 //------------------------------meet-------------------------------------------
6625 // Compute the MEET of two types. It returns a new Type object.
6626 const Type *TypeFunc::xmeet( const Type *t ) const {
6627 // Perform a fast test for common case; meeting the same types together.
6628 if( this == t ) return this; // Meeting same type-rep?
6629
6630 // Current "this->_base" is Func
6631 switch (t->base()) { // switch on original type
6632
6633 case Bottom: // Ye Olde Default
6634 return t;
6635
6636 default: // All else is a mistake
6637 typerr(t);
6638
6639 case Top:
6640 break;
6641 }
6642 return this; // Return the double constant
6643 }
6644
6645 //------------------------------xdual------------------------------------------
6646 // Dual: compute field-by-field dual
6647 const Type *TypeFunc::xdual() const {
6648 return this;
6649 }
6650
6651 //------------------------------eq---------------------------------------------
6652 // Structural equality check for Type representations
6653 bool TypeFunc::eq( const Type *t ) const {
6654 const TypeFunc *a = (const TypeFunc*)t;
6655 return _domain == a->_domain &&
6656 _range == a->_range;
6657 }
6658
6659 //------------------------------hash-------------------------------------------
6660 // Type-specific hashing function.
6661 uint TypeFunc::hash(void) const {
6662 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6663 }
6664
6665 //------------------------------dump2------------------------------------------
6666 // Dump Function Type
6667 #ifndef PRODUCT
6668 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6669 if( _range->cnt() <= Parms )
6670 st->print("void");
6671 else {
6672 uint i;
6673 for (i = Parms; i < _range->cnt()-1; i++) {
6674 _range->field_at(i)->dump2(d,depth,st);
6675 st->print("/");
6676 }
6677 _range->field_at(i)->dump2(d,depth,st);
6678 }
6679 st->print(" ");
6680 st->print("( ");
6681 if( !depth || d[this] ) { // Check for recursive dump
6682 st->print("...)");
6683 return;
6684 }
6685 d.Insert((void*)this,(void*)this); // Stop recursion
6686 if (Parms < _domain->cnt())
6687 _domain->field_at(Parms)->dump2(d,depth-1,st);
6688 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6689 st->print(", ");
6690 _domain->field_at(i)->dump2(d,depth-1,st);
6691 }
6692 st->print(" )");
6693 }
6694 #endif
6695
6696 //------------------------------singleton--------------------------------------
6697 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6698 // constants (Ldi nodes). Singletons are integer, float or double constants
6699 // or a single symbol.
6700 bool TypeFunc::singleton(void) const {
6701 return false; // Never a singleton
6702 }
6703
6704 bool TypeFunc::empty(void) const {
6705 return false; // Never empty
6706 }
6707
6708
6709 BasicType TypeFunc::return_type() const{
6710 if (range()->cnt() == TypeFunc::Parms) {
6711 return T_VOID;
6712 }
6713 return range()->field_at(TypeFunc::Parms)->basic_type();
6714 }
|
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 "precompiled.hpp"
26 #include "ci/ciFlatArrayKlass.hpp"
27 #include "ci/ciField.hpp"
28 #include "ci/ciInlineKlass.hpp"
29 #include "ci/ciMethodData.hpp"
30 #include "ci/ciTypeFlow.hpp"
31 #include "classfile/javaClasses.hpp"
32 #include "classfile/symbolTable.hpp"
33 #include "compiler/compileLog.hpp"
34 #include "libadt/dict.hpp"
35 #include "memory/oopFactory.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "oops/instanceKlass.hpp"
38 #include "oops/instanceMirrorKlass.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/typeArrayKlass.hpp"
41 #include "opto/matcher.hpp"
42 #include "opto/node.hpp"
43 #include "opto/opcodes.hpp"
44 #include "opto/type.hpp"
45 #include "utilities/checkedCast.hpp"
46 #include "utilities/powerOfTwo.hpp"
47 #include "utilities/stringUtils.hpp"
48
49 // Portions of code courtesy of Clifford Click
50
51 // Optimization - Graph Style
52
53 // Dictionary of types shared among compilations.
54 Dict* Type::_shared_type_dict = nullptr;
55 const Type::Offset Type::Offset::top(Type::OffsetTop);
56 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
57
58 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
59 // Either is 'TOP' offset? Return the other offset!
60 if (_offset == OffsetTop) return other;
61 if (other._offset == OffsetTop) return *this;
62 // If either is different, return 'BOTTOM' offset
63 if (_offset != other._offset) return bottom;
64 return Offset(_offset);
65 }
66
67 const Type::Offset Type::Offset::dual() const {
68 if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
69 if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
70 return Offset(_offset); // Map everything else into self
71 }
72
73 const Type::Offset Type::Offset::add(intptr_t offset) const {
74 // Adding to 'TOP' offset? Return 'TOP'!
75 if (_offset == OffsetTop || offset == OffsetTop) return top;
76 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
77 if (_offset == OffsetBot || offset == OffsetBot) return bottom;
78 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
79 offset += (intptr_t)_offset;
80 if (offset != (int)offset || offset == OffsetTop) return bottom;
81
82 // assert( _offset >= 0 && _offset+offset >= 0, "" );
83 // It is possible to construct a negative offset during PhaseCCP
84
85 return Offset((int)offset); // Sum valid offsets
86 }
87
88 void Type::Offset::dump2(outputStream *st) const {
89 if (_offset == 0) {
90 return;
91 } else if (_offset == OffsetTop) {
92 st->print("+top");
93 }
94 else if (_offset == OffsetBot) {
95 st->print("+bot");
96 } else if (_offset) {
97 st->print("+%d", _offset);
98 }
99 }
100
101 // Array which maps compiler types to Basic Types
102 const Type::TypeInfo Type::_type_info[Type::lastype] = {
103 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
104 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
105 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
106 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
107 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
108 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
109 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
110 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
111 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
112 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
113 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
114
115 #if defined(PPC64)
116 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
117 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
118 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
119 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
254 case ciTypeFlow::StateVector::T_NULL:
255 assert(type == ciTypeFlow::StateVector::null_type(), "");
256 return TypePtr::NULL_PTR;
257
258 case ciTypeFlow::StateVector::T_LONG2:
259 // The ciTypeFlow pass pushes a long, then the half.
260 // We do the same.
261 assert(type == ciTypeFlow::StateVector::long2_type(), "");
262 return TypeInt::TOP;
263
264 case ciTypeFlow::StateVector::T_DOUBLE2:
265 // The ciTypeFlow pass pushes double, then the half.
266 // Our convention is the same.
267 assert(type == ciTypeFlow::StateVector::double2_type(), "");
268 return Type::TOP;
269
270 case T_ADDRESS:
271 assert(type->is_return_address(), "");
272 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
273
274 case T_OBJECT:
275 return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
276
277 default:
278 // make sure we did not mix up the cases:
279 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
280 assert(type != ciTypeFlow::StateVector::top_type(), "");
281 assert(type != ciTypeFlow::StateVector::null_type(), "");
282 assert(type != ciTypeFlow::StateVector::long2_type(), "");
283 assert(type != ciTypeFlow::StateVector::double2_type(), "");
284 assert(!type->is_return_address(), "");
285
286 return Type::get_const_type(type);
287 }
288 }
289
290
291 //-----------------------make_from_constant------------------------------------
292 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
293 int stable_dimension, bool is_narrow_oop,
294 bool is_autobox_cache) {
295 switch (constant.basic_type()) {
296 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
563 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
564 ffalse[0] = Type::CONTROL;
565 ffalse[1] = Type::TOP;
566 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
567
568 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
569 fneither[0] = Type::TOP;
570 fneither[1] = Type::TOP;
571 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
572
573 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
574 ftrue[0] = Type::TOP;
575 ftrue[1] = Type::CONTROL;
576 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
577
578 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
579 floop[0] = Type::CONTROL;
580 floop[1] = TypeInt::INT;
581 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
582
583 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
584 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
585 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
586
587 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
588 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
589
590 const Type **fmembar = TypeTuple::fields(0);
591 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
592
593 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
594 fsc[0] = TypeInt::CC;
595 fsc[1] = Type::MEMORY;
596 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
597
598 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
599 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
600 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
601 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
602 false, 0, Offset(oopDesc::mark_offset_in_bytes()));
603 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
604 false, 0, Offset(oopDesc::klass_offset_in_bytes()));
605 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
606
607 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, Offset::bottom);
608
609 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
610 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
611
612 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
613
614 mreg2type[Op_Node] = Type::BOTTOM;
615 mreg2type[Op_Set ] = 0;
616 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
617 mreg2type[Op_RegI] = TypeInt::INT;
618 mreg2type[Op_RegP] = TypePtr::BOTTOM;
619 mreg2type[Op_RegF] = Type::FLOAT;
620 mreg2type[Op_RegD] = Type::DOUBLE;
621 mreg2type[Op_RegL] = TypeLong::LONG;
622 mreg2type[Op_RegFlags] = TypeInt::CC;
623
624 GrowableArray<ciInstanceKlass*> array_interfaces;
625 array_interfaces.push(current->env()->Cloneable_klass());
626 array_interfaces.push(current->env()->Serializable_klass());
627 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
628 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
629
630 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
631
632 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
633
634 #ifdef _LP64
635 if (UseCompressedOops) {
636 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
637 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
638 } else
639 #endif
640 {
641 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
642 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Offset::bottom);
643 }
644 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Offset::bottom);
645 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Offset::bottom);
646 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Offset::bottom);
647 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Offset::bottom);
648 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Offset::bottom);
649 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Offset::bottom);
650 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Offset::bottom);
651 TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true), nullptr, false, Offset::bottom);
652
653 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
654 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
655 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
656 TypeAryPtr::_array_body_type[T_PRIMITIVE_OBJECT] = TypeAryPtr::OOPS;
657 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
658 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
659 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
660 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
661 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
662 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
663 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
664 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
665 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
666
667 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0));
668 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
669
670 const Type **fi2c = TypeTuple::fields(2);
671 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
672 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
673 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
674
675 const Type **intpair = TypeTuple::fields(2);
676 intpair[0] = TypeInt::INT;
677 intpair[1] = TypeInt::INT;
678 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
679
680 const Type **longpair = TypeTuple::fields(2);
681 longpair[0] = TypeLong::LONG;
682 longpair[1] = TypeLong::LONG;
683 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
684
685 const Type **intccpair = TypeTuple::fields(2);
686 intccpair[0] = TypeInt::INT;
687 intccpair[1] = TypeInt::CC;
688 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
689
690 const Type **longccpair = TypeTuple::fields(2);
691 longccpair[0] = TypeLong::LONG;
692 longccpair[1] = TypeInt::CC;
693 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
694
695 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
696 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
697 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
698 _const_basic_type[T_CHAR] = TypeInt::CHAR;
699 _const_basic_type[T_BYTE] = TypeInt::BYTE;
700 _const_basic_type[T_SHORT] = TypeInt::SHORT;
701 _const_basic_type[T_INT] = TypeInt::INT;
702 _const_basic_type[T_LONG] = TypeLong::LONG;
703 _const_basic_type[T_FLOAT] = Type::FLOAT;
704 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
705 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
706 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
707 _const_basic_type[T_PRIMITIVE_OBJECT] = TypeInstPtr::BOTTOM;
708 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
709 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
710 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
711
712 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
713 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
714 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
715 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
716 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
717 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
718 _zero_type[T_INT] = TypeInt::ZERO;
719 _zero_type[T_LONG] = TypeLong::ZERO;
720 _zero_type[T_FLOAT] = TypeF::ZERO;
721 _zero_type[T_DOUBLE] = TypeD::ZERO;
722 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
723 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
724 _zero_type[T_PRIMITIVE_OBJECT] = TypePtr::NULL_PTR;
725 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
726 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
727
728 // get_zero_type() should not happen for T_CONFLICT
729 _zero_type[T_CONFLICT]= nullptr;
730
731 TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
732 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
733
734 if (Matcher::supports_scalable_vector()) {
735 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
736 }
737
738 // Vector predefined types, it needs initialized _const_basic_type[].
739 if (Matcher::vector_size_supported(T_BYTE,4)) {
740 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
741 }
742 if (Matcher::vector_size_supported(T_FLOAT,2)) {
743 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
744 }
2161
2162 bool TypeLong::empty(void) const {
2163 return _lo > _hi;
2164 }
2165
2166 //=============================================================================
2167 // Convenience common pre-built types.
2168 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2169 const TypeTuple *TypeTuple::IFFALSE;
2170 const TypeTuple *TypeTuple::IFTRUE;
2171 const TypeTuple *TypeTuple::IFNEITHER;
2172 const TypeTuple *TypeTuple::LOOPBODY;
2173 const TypeTuple *TypeTuple::MEMBAR;
2174 const TypeTuple *TypeTuple::STORECONDITIONAL;
2175 const TypeTuple *TypeTuple::START_I2C;
2176 const TypeTuple *TypeTuple::INT_PAIR;
2177 const TypeTuple *TypeTuple::LONG_PAIR;
2178 const TypeTuple *TypeTuple::INT_CC_PAIR;
2179 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2180
2181 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2182 for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2183 ciField* field = vk->nonstatic_field_at(j);
2184 // TODO 8325106 The field could be null free, right? Shouldn't we set the type to null-free here?
2185 BasicType bt = field->type()->basic_type();
2186 const Type* ft = Type::get_const_type(field->type());
2187 field_array[pos++] = ft;
2188 if (type2size[bt] == 2) {
2189 field_array[pos++] = Type::HALF;
2190 }
2191 }
2192 }
2193
2194 //------------------------------make-------------------------------------------
2195 // Make a TypeTuple from the range of a method signature
2196 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2197 ciType* return_type = sig->return_type();
2198 uint arg_cnt = return_type->size();
2199 if (ret_vt_fields) {
2200 arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2201 // InlineTypeNode::IsInit field used for null checking
2202 arg_cnt++;
2203 }
2204 const Type **field_array = fields(arg_cnt);
2205 switch (return_type->basic_type()) {
2206 case T_LONG:
2207 field_array[TypeFunc::Parms] = TypeLong::LONG;
2208 field_array[TypeFunc::Parms+1] = Type::HALF;
2209 break;
2210 case T_DOUBLE:
2211 field_array[TypeFunc::Parms] = Type::DOUBLE;
2212 field_array[TypeFunc::Parms+1] = Type::HALF;
2213 break;
2214 case T_OBJECT:
2215 if (return_type->is_inlinetype() && ret_vt_fields) {
2216 uint pos = TypeFunc::Parms;
2217 field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2218 collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2219 // InlineTypeNode::IsInit field used for null checking
2220 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2221 break;
2222 } else {
2223 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2224 }
2225 break;
2226 case T_ARRAY:
2227 case T_BOOLEAN:
2228 case T_CHAR:
2229 case T_FLOAT:
2230 case T_BYTE:
2231 case T_SHORT:
2232 case T_INT:
2233 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2234 break;
2235 case T_VOID:
2236 break;
2237 default:
2238 ShouldNotReachHere();
2239 }
2240 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2241 }
2242
2243 // Make a TypeTuple from the domain of a method signature
2244 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2245 ciSignature* sig = method->signature();
2246 uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2247 if (vt_fields_as_args) {
2248 arg_cnt = 0;
2249 assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2250 for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2251 arg_cnt += type2size[(*sig_cc)._bt];
2252 }
2253 }
2254
2255 uint pos = TypeFunc::Parms;
2256 const Type** field_array = fields(arg_cnt);
2257 if (!method->is_static()) {
2258 ciInstanceKlass* recv = method->holder();
2259 if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2260 collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2261 } else {
2262 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2263 }
2264 }
2265
2266 int i = 0;
2267 while (pos < TypeFunc::Parms + arg_cnt) {
2268 ciType* type = sig->type_at(i);
2269 BasicType bt = type->basic_type();
2270
2271 switch (bt) {
2272 case T_LONG:
2273 field_array[pos++] = TypeLong::LONG;
2274 field_array[pos++] = Type::HALF;
2275 break;
2276 case T_DOUBLE:
2277 field_array[pos++] = Type::DOUBLE;
2278 field_array[pos++] = Type::HALF;
2279 break;
2280 case T_OBJECT:
2281 if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2282 // InlineTypeNode::IsInit field used for null checking
2283 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2284 collect_inline_fields(type->as_inline_klass(), field_array, pos);
2285 } else {
2286 field_array[pos++] = get_const_type(type, interface_handling);
2287 }
2288 break;
2289 case T_ARRAY:
2290 case T_FLOAT:
2291 case T_INT:
2292 field_array[pos++] = get_const_type(type, interface_handling);
2293 break;
2294 case T_BOOLEAN:
2295 case T_CHAR:
2296 case T_BYTE:
2297 case T_SHORT:
2298 field_array[pos++] = TypeInt::INT;
2299 break;
2300 default:
2301 ShouldNotReachHere();
2302 }
2303 i++;
2304 }
2305 assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2306
2307 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2308 }
2309
2310 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2311 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2312 }
2313
2314 //------------------------------fields-----------------------------------------
2315 // Subroutine call type with space allocated for argument types
2316 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2317 const Type **TypeTuple::fields( uint arg_cnt ) {
2318 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2319 flds[TypeFunc::Control ] = Type::CONTROL;
2320 flds[TypeFunc::I_O ] = Type::ABIO;
2321 flds[TypeFunc::Memory ] = Type::MEMORY;
2322 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2323 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2324
2325 return flds;
2420 if (_fields[i]->empty()) return true;
2421 }
2422 return false;
2423 }
2424
2425 //=============================================================================
2426 // Convenience common pre-built types.
2427
2428 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2429 // Certain normalizations keep us sane when comparing types.
2430 // We do not want arrayOop variables to differ only by the wideness
2431 // of their index types. Pick minimum wideness, since that is the
2432 // forced wideness of small ranges anyway.
2433 if (size->_widen != Type::WidenMin)
2434 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2435 else
2436 return size;
2437 }
2438
2439 //------------------------------make-------------------------------------------
2440 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2441 bool flat, bool not_flat, bool not_null_free) {
2442 if (UseCompressedOops && elem->isa_oopptr()) {
2443 elem = elem->make_narrowoop();
2444 }
2445 size = normalize_array_size(size);
2446 return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free))->hashcons();
2447 }
2448
2449 //------------------------------meet-------------------------------------------
2450 // Compute the MEET of two types. It returns a new Type object.
2451 const Type *TypeAry::xmeet( const Type *t ) const {
2452 // Perform a fast test for common case; meeting the same types together.
2453 if( this == t ) return this; // Meeting same type-rep?
2454
2455 // Current "this->_base" is Ary
2456 switch (t->base()) { // switch on original type
2457
2458 case Bottom: // Ye Olde Default
2459 return t;
2460
2461 default: // All else is a mistake
2462 typerr(t);
2463
2464 case Array: { // Meeting 2 arrays?
2465 const TypeAry *a = t->is_ary();
2466 return TypeAry::make(_elem->meet_speculative(a->_elem),
2467 _size->xmeet(a->_size)->is_int(),
2468 _stable && a->_stable,
2469 _flat && a->_flat,
2470 _not_flat && a->_not_flat,
2471 _not_null_free && a->_not_null_free);
2472 }
2473 case Top:
2474 break;
2475 }
2476 return this; // Return the double constant
2477 }
2478
2479 //------------------------------xdual------------------------------------------
2480 // Dual: compute field-by-field dual
2481 const Type *TypeAry::xdual() const {
2482 const TypeInt* size_dual = _size->dual()->is_int();
2483 size_dual = normalize_array_size(size_dual);
2484 return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free);
2485 }
2486
2487 //------------------------------eq---------------------------------------------
2488 // Structural equality check for Type representations
2489 bool TypeAry::eq( const Type *t ) const {
2490 const TypeAry *a = (const TypeAry*)t;
2491 return _elem == a->_elem &&
2492 _stable == a->_stable &&
2493 _size == a->_size &&
2494 _flat == a->_flat &&
2495 _not_flat == a->_not_flat &&
2496 _not_null_free == a->_not_null_free;
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);
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);
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);
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 _elem->dump2(d, depth, st);
2543 st->print("[");
2544 _size->dump2(d, depth, st);
2545 st->print("]");
2546 }
2547 #endif
2548
2549 //------------------------------singleton--------------------------------------
2550 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2551 // constants (Ldi nodes). Singletons are integer, float or double constants
2552 // or a single symbol.
2553 bool TypeAry::singleton(void) const {
2554 return false; // Never a singleton
2555 }
2556
2557 bool TypeAry::empty(void) const {
2558 return _elem->empty() || _size->empty();
2559 }
2560
2561 //--------------------------ary_must_be_exact----------------------------------
2562 bool TypeAry::ary_must_be_exact() const {
2563 // This logic looks at the element type of an array, and returns true
2564 // if the element type is either a primitive or a final instance class.
2565 // In such cases, an array built on this ary must have no subclasses.
2566 if (_elem == BOTTOM) return false; // general array not exact
2567 if (_elem == TOP ) return false; // inverted general array not exact
2568 const TypeOopPtr* toop = nullptr;
2569 if (UseCompressedOops && _elem->isa_narrowoop()) {
2570 toop = _elem->make_ptr()->isa_oopptr();
2571 } else {
2572 toop = _elem->isa_oopptr();
2573 }
2574 if (!toop) return true; // a primitive type, like int
2575 if (!toop->is_loaded()) return false; // unloaded class
2576 const TypeInstPtr* tinst;
2577 if (_elem->isa_narrowoop())
2578 tinst = _elem->make_ptr()->isa_instptr();
2579 else
2580 tinst = _elem->isa_instptr();
2581 if (tinst) {
2582 if (tinst->instance_klass()->is_final()) {
2583 // TODO 8325106 Fix comment
2584 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2585 if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2586 return false;
2587 }
2588 return true;
2589 }
2590 return false;
2591 }
2592 const TypeAryPtr* tap;
2593 if (_elem->isa_narrowoop())
2594 tap = _elem->make_ptr()->isa_aryptr();
2595 else
2596 tap = _elem->isa_aryptr();
2597 if (tap)
2598 return tap->ary()->ary_must_be_exact();
2599 return false;
2600 }
2601
2602 //==============================TypeVect=======================================
2603 // Convenience common pre-built types.
2604 const TypeVect *TypeVect::VECTA = nullptr; // vector length agnostic
2605 const TypeVect *TypeVect::VECTS = nullptr; // 32-bit vectors
2606 const TypeVect *TypeVect::VECTD = nullptr; // 64-bit vectors
2607 const TypeVect *TypeVect::VECTX = nullptr; // 128-bit vectors
2608 const TypeVect *TypeVect::VECTY = nullptr; // 256-bit vectors
2609 const TypeVect *TypeVect::VECTZ = nullptr; // 512-bit vectors
2610 const TypeVect *TypeVect::VECTMASK = nullptr; // predicate/mask vector
2611
2767
2768 //=============================================================================
2769 // Convenience common pre-built types.
2770 const TypePtr *TypePtr::NULL_PTR;
2771 const TypePtr *TypePtr::NOTNULL;
2772 const TypePtr *TypePtr::BOTTOM;
2773
2774 //------------------------------meet-------------------------------------------
2775 // Meet over the PTR enum
2776 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2777 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2778 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2779 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2780 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2781 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2782 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2783 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2784 };
2785
2786 //------------------------------make-------------------------------------------
2787 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2788 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2789 }
2790
2791 //------------------------------cast_to_ptr_type-------------------------------
2792 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2793 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2794 if( ptr == _ptr ) return this;
2795 return make(_base, ptr, _offset, _speculative, _inline_depth);
2796 }
2797
2798 //------------------------------get_con----------------------------------------
2799 intptr_t TypePtr::get_con() const {
2800 assert( _ptr == Null, "" );
2801 return offset();
2802 }
2803
2804 //------------------------------meet-------------------------------------------
2805 // Compute the MEET of two types. It returns a new Type object.
2806 const Type *TypePtr::xmeet(const Type *t) const {
2807 const Type* res = xmeet_helper(t);
2808 if (res->isa_ptr() == nullptr) {
2809 return res;
2810 }
2811
2812 const TypePtr* res_ptr = res->is_ptr();
2813 if (res_ptr->speculative() != nullptr) {
2814 // type->speculative() is null means that speculation is no better
2815 // than type, i.e. type->speculative() == type. So there are 2
2816 // ways to represent the fact that we have no useful speculative
2817 // data and we should use a single one to be able to test for
2818 // equality between types. Check whether type->speculative() ==
2819 // type and set speculative to null if it is the case.
2820 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2821 return res_ptr->remove_speculative();
2852 int depth = meet_inline_depth(tp->inline_depth());
2853 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2854 }
2855 case RawPtr: // For these, flip the call around to cut down
2856 case OopPtr:
2857 case InstPtr: // on the cases I have to handle.
2858 case AryPtr:
2859 case MetadataPtr:
2860 case KlassPtr:
2861 case InstKlassPtr:
2862 case AryKlassPtr:
2863 return t->xmeet(this); // Call in reverse direction
2864 default: // All else is a mistake
2865 typerr(t);
2866
2867 }
2868 return this;
2869 }
2870
2871 //------------------------------meet_offset------------------------------------
2872 Type::Offset TypePtr::meet_offset(int offset) const {
2873 return _offset.meet(Offset(offset));
2874 }
2875
2876 //------------------------------dual_offset------------------------------------
2877 Type::Offset TypePtr::dual_offset() const {
2878 return _offset.dual();
2879 }
2880
2881 //------------------------------xdual------------------------------------------
2882 // Dual: compute field-by-field dual
2883 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2884 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2885 };
2886 const Type *TypePtr::xdual() const {
2887 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2888 }
2889
2890 //------------------------------xadd_offset------------------------------------
2891 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2892 return _offset.add(offset);
2893 }
2894
2895 //------------------------------add_offset-------------------------------------
2896 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2897 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2898 }
2899
2900 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2901 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2902 }
2903
2904 //------------------------------eq---------------------------------------------
2905 // Structural equality check for Type representations
2906 bool TypePtr::eq( const Type *t ) const {
2907 const TypePtr *a = (const TypePtr*)t;
2908 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2909 }
2910
2911 //------------------------------hash-------------------------------------------
2912 // Type-specific hashing function.
2913 uint TypePtr::hash(void) const {
2914 return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2915 }
2916
2917 /**
2918 * Return same type without a speculative part
2919 */
2920 const TypePtr* TypePtr::remove_speculative() const {
2921 if (_speculative == nullptr) {
2922 return this;
2923 }
2924 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2925 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2926 }
2927
2928 /**
2929 * Return same type but drop speculative part if we know we won't use
2930 * it
2931 */
2932 const Type* TypePtr::cleanup_speculative() const {
2933 if (speculative() == nullptr) {
2934 return this;
3160 }
3161 // We already know the speculative type is always null
3162 if (speculative_always_null()) {
3163 return false;
3164 }
3165 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3166 return false;
3167 }
3168 return true;
3169 }
3170
3171 //------------------------------dump2------------------------------------------
3172 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3173 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3174 };
3175
3176 #ifndef PRODUCT
3177 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3178 if( _ptr == Null ) st->print("null");
3179 else st->print("%s *", ptr_msg[_ptr]);
3180 _offset.dump2(st);
3181 dump_inline_depth(st);
3182 dump_speculative(st);
3183 }
3184
3185 /**
3186 *dump the speculative part of the type
3187 */
3188 void TypePtr::dump_speculative(outputStream *st) const {
3189 if (_speculative != nullptr) {
3190 st->print(" (speculative=");
3191 _speculative->dump_on(st);
3192 st->print(")");
3193 }
3194 }
3195
3196 /**
3197 *dump the inline depth of the type
3198 */
3199 void TypePtr::dump_inline_depth(outputStream *st) const {
3200 if (_inline_depth != InlineDepthBottom) {
3201 if (_inline_depth == InlineDepthTop) {
3202 st->print(" (inline_depth=InlineDepthTop)");
3203 } else {
3204 st->print(" (inline_depth=%d)", _inline_depth);
3205 }
3206 }
3207 }
3208 #endif
3209
3210 //------------------------------singleton--------------------------------------
3211 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3212 // constants
3213 bool TypePtr::singleton(void) const {
3214 // TopPTR, Null, AnyNull, Constant are all singletons
3215 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3216 }
3217
3218 bool TypePtr::empty(void) const {
3219 return (_offset == Offset::top) || above_centerline(_ptr);
3220 }
3221
3222 //=============================================================================
3223 // Convenience common pre-built types.
3224 const TypeRawPtr *TypeRawPtr::BOTTOM;
3225 const TypeRawPtr *TypeRawPtr::NOTNULL;
3226
3227 //------------------------------make-------------------------------------------
3228 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3229 assert( ptr != Constant, "what is the constant?" );
3230 assert( ptr != Null, "Use TypePtr for null" );
3231 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3232 }
3233
3234 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3235 assert( bits, "Use TypePtr for null" );
3236 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3237 }
3238
3239 //------------------------------cast_to_ptr_type-------------------------------
3591 void TypeInterfaces::verify_is_loaded() const {
3592 for (int i = 0; i < _list.length(); i++) {
3593 ciKlass* interface = _list.at(i);
3594 assert(interface->is_loaded(), "Interface not loaded");
3595 }
3596 }
3597 #endif
3598
3599 // Can't be implemented because there's no way to know if the type is above or below the center line.
3600 const Type* TypeInterfaces::xmeet(const Type* t) const {
3601 ShouldNotReachHere();
3602 return Type::xmeet(t);
3603 }
3604
3605 bool TypeInterfaces::singleton(void) const {
3606 ShouldNotReachHere();
3607 return Type::singleton();
3608 }
3609
3610 //------------------------------TypeOopPtr-------------------------------------
3611 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3612 int instance_id, const TypePtr* speculative, int inline_depth)
3613 : TypePtr(t, ptr, offset, speculative, inline_depth),
3614 _const_oop(o), _klass(k),
3615 _interfaces(interfaces),
3616 _klass_is_exact(xk),
3617 _is_ptr_to_narrowoop(false),
3618 _is_ptr_to_narrowklass(false),
3619 _is_ptr_to_boxed_value(false),
3620 _instance_id(instance_id) {
3621 #ifdef ASSERT
3622 if (klass() != nullptr && klass()->is_loaded()) {
3623 interfaces->verify_is_loaded();
3624 }
3625 #endif
3626 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3627 (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3628 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3629 }
3630 #ifdef _LP64
3631 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3632 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3633 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3634 } else if (klass() == nullptr) {
3635 // Array with unknown body type
3636 assert(this->isa_aryptr(), "only arrays without klass");
3637 _is_ptr_to_narrowoop = UseCompressedOops;
3638 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3639 if (klass()->is_obj_array_klass()) {
3640 _is_ptr_to_narrowoop = true;
3641 } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3642 // Check if the field of the inline type array element contains oops
3643 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3644 int foffset = field_offset.get() + vk->first_field_offset();
3645 ciField* field = vk->get_field_by_offset(foffset, false);
3646 assert(field != nullptr, "missing field");
3647 BasicType bt = field->layout_type();
3648 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3649 }
3650 } else if (klass()->is_instance_klass()) {
3651 if (this->isa_klassptr()) {
3652 // Perm objects don't use compressed references
3653 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3654 // unsafe access
3655 _is_ptr_to_narrowoop = UseCompressedOops;
3656 } else {
3657 assert(this->isa_instptr(), "must be an instance ptr.");
3658 if (klass() == ciEnv::current()->Class_klass() &&
3659 (this->offset() == java_lang_Class::klass_offset() ||
3660 this->offset() == java_lang_Class::array_klass_offset())) {
3661 // Special hidden fields from the Class.
3662 assert(this->isa_instptr(), "must be an instance ptr.");
3663 _is_ptr_to_narrowoop = false;
3664 } else if (klass() == ciEnv::current()->Class_klass() &&
3665 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3666 // Static fields
3667 ciField* field = nullptr;
3668 if (const_oop() != nullptr) {
3669 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3670 // TODO 8325106 remove?
3671 if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3672 // Special hidden field that contains the oop of the default inline type
3673 // basic_elem_type = T_PRIMITIVE_OBJECT;
3674 _is_ptr_to_narrowoop = UseCompressedOops;
3675 } else {
3676 field = k->get_field_by_offset(this->offset(), true);
3677 if (field != nullptr) {
3678 BasicType basic_elem_type = field->layout_type();
3679 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3680 } else {
3681 // unsafe access
3682 _is_ptr_to_narrowoop = UseCompressedOops;
3683 }
3684 }
3685 }
3686 } else {
3687 // Instance fields which contains a compressed oop references.
3688 ciInstanceKlass* ik = klass()->as_instance_klass();
3689 ciField* field = ik->get_field_by_offset(this->offset(), false);
3690 if (field != nullptr) {
3691 BasicType basic_elem_type = field->layout_type();
3692 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3693 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3694 // Compile::find_alias_type() cast exactness on all types to verify
3695 // that it does not affect alias type.
3696 _is_ptr_to_narrowoop = UseCompressedOops;
3697 } else {
3698 // Type for the copy start in LibraryCallKit::inline_native_clone().
3699 _is_ptr_to_narrowoop = UseCompressedOops;
3700 }
3701 }
3702 }
3703 }
3704 }
3705 #endif
3706 }
3707
3708 //------------------------------make-------------------------------------------
3709 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3710 const TypePtr* speculative, int inline_depth) {
3711 assert(ptr != Constant, "no constant generic pointers");
3712 ciKlass* k = Compile::current()->env()->Object_klass();
3713 bool xk = false;
3714 ciObject* o = nullptr;
3715 const TypeInterfaces* interfaces = TypeInterfaces::make();
3716 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3717 }
3718
3719
3720 //------------------------------cast_to_ptr_type-------------------------------
3721 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3722 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3723 if( ptr == _ptr ) return this;
3724 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3725 }
3726
3727 //-----------------------------cast_to_instance_id----------------------------
3728 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3729 // There are no instances of a general oop.
3730 // Return self unchanged.
3731 return this;
3732 }
3733
3734 //-----------------------------cast_to_exactness-------------------------------
3735 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3736 // There is no such thing as an exact general oop.
3737 // Return self unchanged.
3738 return this;
3739 }
3740
3741 //------------------------------as_klass_type----------------------------------
3742 // Return the klass type corresponding to this instance or array type.
3743 // It is the type that is loaded from an object of this type.
3744 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3745 ShouldNotReachHere();
3746 return nullptr;
3747 }
3748
3749 //------------------------------meet-------------------------------------------
3750 // Compute the MEET of two types. It returns a new Type object.
3751 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3752 // Perform a fast test for common case; meeting the same types together.
3753 if( this == t ) return this; // Meeting same type-rep?
3754
3755 // Current "this->_base" is OopPtr
3756 switch (t->base()) { // switch on original type
3757
3758 case Int: // Mixing ints & oops happens when javac
3759 case Long: // reuses local variables
3760 case FloatTop:
3766 case NarrowOop:
3767 case NarrowKlass:
3768 case Bottom: // Ye Olde Default
3769 return Type::BOTTOM;
3770 case Top:
3771 return this;
3772
3773 default: // All else is a mistake
3774 typerr(t);
3775
3776 case RawPtr:
3777 case MetadataPtr:
3778 case KlassPtr:
3779 case InstKlassPtr:
3780 case AryKlassPtr:
3781 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3782
3783 case AnyPtr: {
3784 // Found an AnyPtr type vs self-OopPtr type
3785 const TypePtr *tp = t->is_ptr();
3786 Offset offset = meet_offset(tp->offset());
3787 PTR ptr = meet_ptr(tp->ptr());
3788 const TypePtr* speculative = xmeet_speculative(tp);
3789 int depth = meet_inline_depth(tp->inline_depth());
3790 switch (tp->ptr()) {
3791 case Null:
3792 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3793 // else fall through:
3794 case TopPTR:
3795 case AnyNull: {
3796 int instance_id = meet_instance_id(InstanceTop);
3797 return make(ptr, offset, instance_id, speculative, depth);
3798 }
3799 case BotPTR:
3800 case NotNull:
3801 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3802 default: typerr(t);
3803 }
3804 }
3805
3806 case OopPtr: { // Meeting to other OopPtrs
3808 int instance_id = meet_instance_id(tp->instance_id());
3809 const TypePtr* speculative = xmeet_speculative(tp);
3810 int depth = meet_inline_depth(tp->inline_depth());
3811 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3812 }
3813
3814 case InstPtr: // For these, flip the call around to cut down
3815 case AryPtr:
3816 return t->xmeet(this); // Call in reverse direction
3817
3818 } // End of switch
3819 return this; // Return the double constant
3820 }
3821
3822
3823 //------------------------------xdual------------------------------------------
3824 // Dual of a pure heap pointer. No relevant klass or oop information.
3825 const Type *TypeOopPtr::xdual() const {
3826 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3827 assert(const_oop() == nullptr, "no constants here");
3828 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());
3829 }
3830
3831 //--------------------------make_from_klass_common-----------------------------
3832 // Computes the element-type given a klass.
3833 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3834 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3835 Compile* C = Compile::current();
3836 Dependencies* deps = C->dependencies();
3837 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3838 // Element is an instance
3839 bool klass_is_exact = false;
3840 if (klass->is_loaded()) {
3841 // Try to set klass_is_exact.
3842 ciInstanceKlass* ik = klass->as_instance_klass();
3843 klass_is_exact = ik->is_final();
3844 if (!klass_is_exact && klass_change
3845 && deps != nullptr && UseUniqueSubclasses) {
3846 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3847 if (sub != nullptr) {
3848 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3849 klass = ik = sub;
3850 klass_is_exact = sub->is_final();
3851 }
3852 }
3853 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3854 !ik->is_interface() && !ik->has_subklass()) {
3855 // Add a dependence; if concrete subclass added we need to recompile
3856 deps->assert_leaf_type(ik);
3857 klass_is_exact = true;
3858 }
3859 }
3860 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3861 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
3862 } else if (klass->is_obj_array_klass()) {
3863 // Element is an object or inline type array. Recursively call ourself.
3864 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3865 // Determine null-free/flat properties
3866 const TypeOopPtr* exact_etype = etype;
3867 if (etype->can_be_inline_type()) {
3868 // Use exact type if element can be an inline type
3869 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3870 }
3871 bool not_null_free = !exact_etype->can_be_inline_type();
3872 bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
3873
3874 // TODO 8325106 Fix comment
3875 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3876 bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
3877 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
3878 // We used to pass NotNull in here, asserting that the sub-arrays
3879 // are all not-null. This is not true in generally, as code can
3880 // slam nullptrs down in the subarrays.
3881 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3882 return arr;
3883 } else if (klass->is_type_array_klass()) {
3884 // Element is an typeArray
3885 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3886 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3887 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3888 // We used to pass NotNull in here, asserting that the array pointer
3889 // is not-null. That was not true in general.
3890 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3891 return arr;
3892 } else if (klass->is_flat_array_klass()) {
3893 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3894 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3895 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
3896 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3897 return arr;
3898 } else {
3899 ShouldNotReachHere();
3900 return nullptr;
3901 }
3902 }
3903
3904 //------------------------------make_from_constant-----------------------------
3905 // Make a java pointer from an oop constant
3906 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3907 assert(!o->is_null_object(), "null object not yet handled here.");
3908
3909 const bool make_constant = require_constant || o->should_be_constant();
3910
3911 ciKlass* klass = o->klass();
3912 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3913 // Element is an instance or inline type
3914 if (make_constant) {
3915 return TypeInstPtr::make(o);
3916 } else {
3917 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3918 }
3919 } else if (klass->is_obj_array_klass()) {
3920 // Element is an object array. Recursively call ourself.
3921 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3922 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3923 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3924 // We used to pass NotNull in here, asserting that the sub-arrays
3925 // are all not-null. This is not true in generally, as code can
3926 // slam nulls down in the subarrays.
3927 if (make_constant) {
3928 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3929 } else {
3930 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3931 }
3932 } else if (klass->is_type_array_klass()) {
3933 // Element is an typeArray
3934 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3935 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3936 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3937 // We used to pass NotNull in here, asserting that the array pointer
3938 // is not-null. That was not true in general.
3939 if (make_constant) {
3940 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3941 } else {
3942 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3943 }
3944 } else if (klass->is_flat_array_klass()) {
3945 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3946 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3947 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true);
3948 // We used to pass NotNull in here, asserting that the sub-arrays
3949 // are all not-null. This is not true in generally, as code can
3950 // slam nullptrs down in the subarrays.
3951 if (make_constant) {
3952 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3953 } else {
3954 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3955 }
3956 }
3957
3958 fatal("unhandled object type");
3959 return nullptr;
3960 }
3961
3962 //------------------------------get_con----------------------------------------
3963 intptr_t TypeOopPtr::get_con() const {
3964 assert( _ptr == Null || _ptr == Constant, "" );
3965 assert(offset() >= 0, "");
3966
3967 if (offset() != 0) {
3968 // After being ported to the compiler interface, the compiler no longer
3969 // directly manipulates the addresses of oops. Rather, it only has a pointer
3970 // to a handle at compile time. This handle is embedded in the generated
3971 // code and dereferenced at the time the nmethod is made. Until that time,
3972 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3973 // have access to the addresses!). This does not seem to currently happen,
3974 // but this assertion here is to help prevent its occurrence.
3975 tty->print_cr("Found oop constant with non-zero offset");
3976 ShouldNotReachHere();
3977 }
3978
3979 return (intptr_t)const_oop()->constant_encoding();
3980 }
3981
3982
3983 //-----------------------------filter------------------------------------------
3984 // Do not allow interface-vs.-noninterface joins to collapse to top.
3985 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3986
3987 const Type* ft = join_helper(kills, include_speculative);
4008 } else {
4009 return one->equals(two) && TypePtr::eq(t);
4010 }
4011 }
4012
4013 //------------------------------hash-------------------------------------------
4014 // Type-specific hashing function.
4015 uint TypeOopPtr::hash(void) const {
4016 return
4017 (uint)(const_oop() ? const_oop()->hash() : 0) +
4018 (uint)_klass_is_exact +
4019 (uint)_instance_id + TypePtr::hash();
4020 }
4021
4022 //------------------------------dump2------------------------------------------
4023 #ifndef PRODUCT
4024 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4025 st->print("oopptr:%s", ptr_msg[_ptr]);
4026 if( _klass_is_exact ) st->print(":exact");
4027 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4028 _offset.dump2(st);
4029 if (_instance_id == InstanceTop)
4030 st->print(",iid=top");
4031 else if (_instance_id != InstanceBot)
4032 st->print(",iid=%d",_instance_id);
4033
4034 dump_inline_depth(st);
4035 dump_speculative(st);
4036 }
4037 #endif
4038
4039 //------------------------------singleton--------------------------------------
4040 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4041 // constants
4042 bool TypeOopPtr::singleton(void) const {
4043 // detune optimizer to not generate constant oop + constant offset as a constant!
4044 // TopPTR, Null, AnyNull, Constant are all singletons
4045 return (offset() == 0) && !below_centerline(_ptr);
4046 }
4047
4048 //------------------------------add_offset-------------------------------------
4049 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4050 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4051 }
4052
4053 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4054 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4055 }
4056
4057 /**
4058 * Return same type without a speculative part
4059 */
4060 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4061 if (_speculative == nullptr) {
4062 return this;
4063 }
4064 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4065 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4066 }
4067
4068 /**
4069 * Return same type but drop speculative part if we know we won't use
4070 * it
4071 */
4072 const Type* TypeOopPtr::cleanup_speculative() const {
4073 // If the klass is exact and the ptr is not null then there's
4074 // nothing that the speculative type can help us with
4147 const TypeInstPtr *TypeInstPtr::BOTTOM;
4148 const TypeInstPtr *TypeInstPtr::MIRROR;
4149 const TypeInstPtr *TypeInstPtr::MARK;
4150 const TypeInstPtr *TypeInstPtr::KLASS;
4151
4152 // Is there a single ciKlass* that can represent that type?
4153 ciKlass* TypeInstPtr::exact_klass_helper() const {
4154 if (_interfaces->empty()) {
4155 return _klass;
4156 }
4157 if (_klass != ciEnv::current()->Object_klass()) {
4158 if (_interfaces->eq(_klass->as_instance_klass())) {
4159 return _klass;
4160 }
4161 return nullptr;
4162 }
4163 return _interfaces->exact_klass();
4164 }
4165
4166 //------------------------------TypeInstPtr-------------------------------------
4167 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4168 bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4169 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4170 _flat_in_array(flat_in_array) {
4171 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4172 assert(k != nullptr &&
4173 (k->is_loaded() || o == nullptr),
4174 "cannot have constants with non-loaded klass");
4175 assert(!klass()->flat_in_array() || flat_in_array, "Should be flat in array");
4176 assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4177 };
4178
4179 //------------------------------make-------------------------------------------
4180 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4181 ciKlass* k,
4182 const TypeInterfaces* interfaces,
4183 bool xk,
4184 ciObject* o,
4185 Offset offset,
4186 bool flat_in_array,
4187 int instance_id,
4188 const TypePtr* speculative,
4189 int inline_depth) {
4190 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4191 // Either const_oop() is null or else ptr is Constant
4192 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4193 "constant pointers must have a value supplied" );
4194 // Ptr is never Null
4195 assert( ptr != Null, "null pointers are not typed" );
4196
4197 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4198 if (ptr == Constant) {
4199 // Note: This case includes meta-object constants, such as methods.
4200 xk = true;
4201 } else if (k->is_loaded()) {
4202 ciInstanceKlass* ik = k->as_instance_klass();
4203 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4204 assert(!ik->is_interface(), "no interface here");
4205 if (xk && ik->is_interface()) xk = false; // no exact interface
4206 }
4207
4208 // Check if this type is known to be flat in arrays
4209 flat_in_array = flat_in_array || k->flat_in_array();
4210
4211 // Now hash this baby
4212 TypeInstPtr *result =
4213 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4214
4215 return result;
4216 }
4217
4218 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4219 if (k->is_instance_klass()) {
4220 if (k->is_loaded()) {
4221 if (k->is_interface() && interface_handling == ignore_interfaces) {
4222 assert(interface, "no interface expected");
4223 k = ciEnv::current()->Object_klass();
4224 const TypeInterfaces* interfaces = TypeInterfaces::make();
4225 return interfaces;
4226 }
4227 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4228 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4229 if (k->is_interface()) {
4230 assert(interface, "no interface expected");
4231 k = ciEnv::current()->Object_klass();
4232 } else {
4233 assert(klass, "no instance klass expected");
4259 switch (bt) {
4260 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
4261 case T_INT: return TypeInt::make(constant.as_int());
4262 case T_CHAR: return TypeInt::make(constant.as_char());
4263 case T_BYTE: return TypeInt::make(constant.as_byte());
4264 case T_SHORT: return TypeInt::make(constant.as_short());
4265 case T_FLOAT: return TypeF::make(constant.as_float());
4266 case T_DOUBLE: return TypeD::make(constant.as_double());
4267 case T_LONG: return TypeLong::make(constant.as_long());
4268 default: break;
4269 }
4270 fatal("Invalid boxed value type '%s'", type2name(bt));
4271 return nullptr;
4272 }
4273
4274 //------------------------------cast_to_ptr_type-------------------------------
4275 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4276 if( ptr == _ptr ) return this;
4277 // Reconstruct _sig info here since not a problem with later lazy
4278 // construction, _sig will show up on demand.
4279 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4280 }
4281
4282
4283 //-----------------------------cast_to_exactness-------------------------------
4284 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4285 if( klass_is_exact == _klass_is_exact ) return this;
4286 if (!_klass->is_loaded()) return this;
4287 ciInstanceKlass* ik = _klass->as_instance_klass();
4288 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4289 assert(!ik->is_interface(), "no interface here");
4290 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4291 }
4292
4293 //-----------------------------cast_to_instance_id----------------------------
4294 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4295 if( instance_id == _instance_id ) return this;
4296 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4297 }
4298
4299 //------------------------------xmeet_unloaded---------------------------------
4300 // Compute the MEET of two InstPtrs when at least one is unloaded.
4301 // Assume classes are different since called after check for same name/class-loader
4302 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4303 Offset off = meet_offset(tinst->offset());
4304 PTR ptr = meet_ptr(tinst->ptr());
4305 int instance_id = meet_instance_id(tinst->instance_id());
4306 const TypePtr* speculative = xmeet_speculative(tinst);
4307 int depth = meet_inline_depth(tinst->inline_depth());
4308
4309 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4310 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4311 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4312 //
4313 // Meet unloaded class with java/lang/Object
4314 //
4315 // Meet
4316 // | Unloaded Class
4317 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4318 // ===================================================================
4319 // TOP | ..........................Unloaded......................|
4320 // AnyNull | U-AN |................Unloaded......................|
4321 // Constant | ... O-NN .................................. | O-BOT |
4322 // NotNull | ... O-NN .................................. | O-BOT |
4323 // BOTTOM | ........................Object-BOTTOM ..................|
4324 //
4325 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4326 //
4327 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4328 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4329 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM; }
4330 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4331 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM; }
4332 else { return TypeInstPtr::NOTNULL; }
4333 }
4334 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4335
4336 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4337 }
4338
4339 // Both are unloaded, not the same class, not Object
4340 // Or meet unloaded with a different loaded class, not java/lang/Object
4341 if (ptr != TypePtr::BotPTR) {
4342 return TypeInstPtr::NOTNULL;
4343 }
4344 return TypeInstPtr::BOTTOM;
4345 }
4346
4347
4348 //------------------------------meet-------------------------------------------
4369 case Top:
4370 return this;
4371
4372 default: // All else is a mistake
4373 typerr(t);
4374
4375 case MetadataPtr:
4376 case KlassPtr:
4377 case InstKlassPtr:
4378 case AryKlassPtr:
4379 case RawPtr: return TypePtr::BOTTOM;
4380
4381 case AryPtr: { // All arrays inherit from Object class
4382 // Call in reverse direction to avoid duplication
4383 return t->is_aryptr()->xmeet_helper(this);
4384 }
4385
4386 case OopPtr: { // Meeting to OopPtrs
4387 // Found a OopPtr type vs self-InstPtr type
4388 const TypeOopPtr *tp = t->is_oopptr();
4389 Offset offset = meet_offset(tp->offset());
4390 PTR ptr = meet_ptr(tp->ptr());
4391 switch (tp->ptr()) {
4392 case TopPTR:
4393 case AnyNull: {
4394 int instance_id = meet_instance_id(InstanceTop);
4395 const TypePtr* speculative = xmeet_speculative(tp);
4396 int depth = meet_inline_depth(tp->inline_depth());
4397 return make(ptr, klass(), _interfaces, klass_is_exact(),
4398 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4399 }
4400 case NotNull:
4401 case BotPTR: {
4402 int instance_id = meet_instance_id(tp->instance_id());
4403 const TypePtr* speculative = xmeet_speculative(tp);
4404 int depth = meet_inline_depth(tp->inline_depth());
4405 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4406 }
4407 default: typerr(t);
4408 }
4409 }
4410
4411 case AnyPtr: { // Meeting to AnyPtrs
4412 // Found an AnyPtr type vs self-InstPtr type
4413 const TypePtr *tp = t->is_ptr();
4414 Offset offset = meet_offset(tp->offset());
4415 PTR ptr = meet_ptr(tp->ptr());
4416 int instance_id = meet_instance_id(InstanceTop);
4417 const TypePtr* speculative = xmeet_speculative(tp);
4418 int depth = meet_inline_depth(tp->inline_depth());
4419 switch (tp->ptr()) {
4420 case Null:
4421 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4422 // else fall through to AnyNull
4423 case TopPTR:
4424 case AnyNull: {
4425 return make(ptr, klass(), _interfaces, klass_is_exact(),
4426 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4427 }
4428 case NotNull:
4429 case BotPTR:
4430 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4431 default: typerr(t);
4432 }
4433 }
4434
4435 /*
4436 A-top }
4437 / | \ } Tops
4438 B-top A-any C-top }
4439 | / | \ | } Any-nulls
4440 B-any | C-any }
4441 | | |
4442 B-con A-con C-con } constants; not comparable across classes
4443 | | |
4444 B-not | C-not }
4445 | \ | / | } not-nulls
4446 B-bot A-not C-bot }
4447 \ | / } Bottoms
4448 A-bot }
4449 */
4450
4451 case InstPtr: { // Meeting 2 Oops?
4452 // Found an InstPtr sub-type vs self-InstPtr type
4453 const TypeInstPtr *tinst = t->is_instptr();
4454 Offset off = meet_offset(tinst->offset());
4455 PTR ptr = meet_ptr(tinst->ptr());
4456 int instance_id = meet_instance_id(tinst->instance_id());
4457 const TypePtr* speculative = xmeet_speculative(tinst);
4458 int depth = meet_inline_depth(tinst->inline_depth());
4459 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4460
4461 ciKlass* tinst_klass = tinst->klass();
4462 ciKlass* this_klass = klass();
4463
4464 ciKlass* res_klass = nullptr;
4465 bool res_xk = false;
4466 bool res_flat_in_array = false;
4467 const Type* res;
4468 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4469
4470 if (kind == UNLOADED) {
4471 // One of these classes has not been loaded
4472 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4473 #ifndef PRODUCT
4474 if (PrintOpto && Verbose) {
4475 tty->print("meet of unloaded classes resulted in: ");
4476 unloaded_meet->dump();
4477 tty->cr();
4478 tty->print(" this == ");
4479 dump();
4480 tty->cr();
4481 tty->print(" tinst == ");
4482 tinst->dump();
4483 tty->cr();
4484 }
4485 #endif
4486 res = unloaded_meet;
4487 } else {
4488 if (kind == NOT_SUBTYPE && instance_id > 0) {
4489 instance_id = InstanceBot;
4490 } else if (kind == LCA) {
4491 instance_id = InstanceBot;
4492 }
4493 ciObject* o = nullptr; // Assume not constant when done
4494 ciObject* this_oop = const_oop();
4495 ciObject* tinst_oop = tinst->const_oop();
4496 if (ptr == Constant) {
4497 if (this_oop != nullptr && tinst_oop != nullptr &&
4498 this_oop->equals(tinst_oop))
4499 o = this_oop;
4500 else if (above_centerline(_ptr)) {
4501 assert(!tinst_klass->is_interface(), "");
4502 o = tinst_oop;
4503 } else if (above_centerline(tinst->_ptr)) {
4504 assert(!this_klass->is_interface(), "");
4505 o = this_oop;
4506 } else
4507 ptr = NotNull;
4508 }
4509 res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4510 }
4511
4512 return res;
4513
4514 } // End of case InstPtr
4515
4516 } // End of switch
4517 return this; // Return the double constant
4518 }
4519
4520 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4521 ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4522 ciKlass* this_klass = this_type->klass();
4523 ciKlass* other_klass = other_type->klass();
4524 bool this_flat_in_array = this_type->flat_in_array();
4525 bool other_flat_in_array = other_type->flat_in_array();
4526 bool this_flat_in_array_orig = this_flat_in_array;
4527 bool other_flat_in_array_orig = other_flat_in_array;
4528 bool this_xk = this_type->klass_is_exact();
4529 bool other_xk = other_type->klass_is_exact();
4530 PTR this_ptr = this_type->ptr();
4531 PTR other_ptr = other_type->ptr();
4532 const TypeInterfaces* this_interfaces = this_type->interfaces();
4533 const TypeInterfaces* other_interfaces = other_type->interfaces();
4534 // Check for easy case; klasses are equal (and perhaps not loaded!)
4535 // If we have constants, then we created oops so classes are loaded
4536 // and we can handle the constants further down. This case handles
4537 // both-not-loaded or both-loaded classes
4538 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4539 res_klass = this_klass;
4540 res_xk = this_xk;
4541 res_flat_in_array = this_flat_in_array;
4542 return QUICK;
4543 }
4544
4545 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4546 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4547 return UNLOADED;
4548 }
4549
4550 // !!! Here's how the symmetry requirement breaks down into invariants:
4551 // If we split one up & one down AND they subtype, take the down man.
4552 // If we split one up & one down AND they do NOT subtype, "fall hard".
4553 // If both are up and they subtype, take the subtype class.
4554 // If both are up and they do NOT subtype, "fall hard".
4555 // If both are down and they subtype, take the supertype class.
4556 // If both are down and they do NOT subtype, "fall hard".
4557 // Constants treated as down.
4558
4559 // Now, reorder the above list; observe that both-down+subtype is also
4560 // "fall hard"; "fall hard" becomes the default case:
4561 // If we split one up & one down AND they subtype, take the down man.
4562 // If both are up and they subtype, take the subtype class.
4563
4564 // If both are down and they subtype, "fall hard".
4565 // If both are down and they do NOT subtype, "fall hard".
4566 // If both are up and they do NOT subtype, "fall hard".
4567 // If we split one up & one down AND they do NOT subtype, "fall hard".
4568
4569 // If a proper subtype is exact, and we return it, we return it exactly.
4570 // If a proper supertype is exact, there can be no subtyping relationship!
4571 // If both types are equal to the subtype, exactness is and-ed below the
4572 // centerline and or-ed above it. (N.B. Constants are always exact.)
4573
4574 // Check for subtyping:
4575 const T* subtype = nullptr;
4576 bool subtype_exact = false;
4577 bool flat_array = false;
4578 if (this_type->is_same_java_type_as(other_type)) {
4579 subtype = this_type;
4580 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4581 flat_array = below_centerline(ptr) ? (this_flat_in_array && other_flat_in_array) : (this_flat_in_array || other_flat_in_array);
4582 } else if (!other_xk && this_type->is_meet_subtype_of(other_type) && (!other_flat_in_array || this_flat_in_array)) {
4583 subtype = this_type; // Pick subtyping class
4584 subtype_exact = this_xk;
4585 flat_array = this_flat_in_array;
4586 } else if (!this_xk && other_type->is_meet_subtype_of(this_type) && (!this_flat_in_array || other_flat_in_array)) {
4587 subtype = other_type; // Pick subtyping class
4588 subtype_exact = other_xk;
4589 flat_array = other_flat_in_array;
4590 }
4591
4592 if (subtype) {
4593 if (above_centerline(ptr)) { // both are up?
4594 this_type = other_type = subtype;
4595 this_xk = other_xk = subtype_exact;
4596 this_flat_in_array = other_flat_in_array = flat_array;
4597 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4598 this_type = other_type; // tinst is down; keep down man
4599 this_xk = other_xk;
4600 this_flat_in_array = other_flat_in_array;
4601 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4602 other_type = this_type; // this is down; keep down man
4603 other_xk = this_xk;
4604 other_flat_in_array = this_flat_in_array;
4605 } else {
4606 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4607 this_flat_in_array = flat_array;
4608 }
4609 }
4610
4611 // Check for classes now being equal
4612 if (this_type->is_same_java_type_as(other_type)) {
4613 // If the klasses are equal, the constants may still differ. Fall to
4614 // NotNull if they do (neither constant is null; that is a special case
4615 // handled elsewhere).
4616 res_klass = this_type->klass();
4617 res_xk = this_xk;
4618 res_flat_in_array = this_flat_in_array;
4619 return SUBTYPE;
4620 } // Else classes are not equal
4621
4622 // Since klasses are different, we require a LCA in the Java
4623 // class hierarchy - which means we have to fall to at least NotNull.
4624 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4625 ptr = NotNull;
4626 }
4627
4628 interfaces = this_interfaces->intersection_with(other_interfaces);
4629
4630 // Now we find the LCA of Java classes
4631 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4632
4633 res_klass = k;
4634 res_xk = false;
4635 res_flat_in_array = this_flat_in_array_orig && other_flat_in_array_orig;
4636
4637 return LCA;
4638 }
4639
4640 //------------------------java_mirror_type--------------------------------------
4641 ciType* TypeInstPtr::java_mirror_type() const {
4642 // must be a singleton type
4643 if( const_oop() == nullptr ) return nullptr;
4644
4645 // must be of type java.lang.Class
4646 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4647 return const_oop()->as_instance()->java_mirror_type();
4648 }
4649
4650
4651 //------------------------------xdual------------------------------------------
4652 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4653 // inheritance mechanism.
4654 const Type *TypeInstPtr::xdual() const {
4655 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4656 }
4657
4658 //------------------------------eq---------------------------------------------
4659 // Structural equality check for Type representations
4660 bool TypeInstPtr::eq( const Type *t ) const {
4661 const TypeInstPtr *p = t->is_instptr();
4662 return
4663 klass()->equals(p->klass()) &&
4664 flat_in_array() == p->flat_in_array() &&
4665 _interfaces->eq(p->_interfaces) &&
4666 TypeOopPtr::eq(p); // Check sub-type stuff
4667 }
4668
4669 //------------------------------hash-------------------------------------------
4670 // Type-specific hashing function.
4671 uint TypeInstPtr::hash(void) const {
4672 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4673 }
4674
4675 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4676 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4677 }
4678
4679
4680 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4681 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4682 }
4683
4684 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4685 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4686 }
4687
4688
4689 //------------------------------dump2------------------------------------------
4690 // Dump oop Type
4691 #ifndef PRODUCT
4692 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4706 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4707 char* buf = ss.as_string(/* c_heap= */false);
4708 StringUtils::replace_no_expand(buf, "\n", "");
4709 st->print_raw(buf);
4710 }
4711 case BotPTR:
4712 if (!WizardMode && !Verbose) {
4713 if( _klass_is_exact ) st->print(":exact");
4714 break;
4715 }
4716 case TopPTR:
4717 case AnyNull:
4718 case NotNull:
4719 st->print(":%s", ptr_msg[_ptr]);
4720 if( _klass_is_exact ) st->print(":exact");
4721 break;
4722 default:
4723 break;
4724 }
4725
4726 _offset.dump2(st);
4727
4728 st->print(" *");
4729
4730 if (flat_in_array() && !klass()->is_inlinetype()) {
4731 st->print(" (flat in array)");
4732 }
4733
4734 if (_instance_id == InstanceTop)
4735 st->print(",iid=top");
4736 else if (_instance_id != InstanceBot)
4737 st->print(",iid=%d",_instance_id);
4738
4739 dump_inline_depth(st);
4740 dump_speculative(st);
4741 }
4742 #endif
4743
4744 //------------------------------add_offset-------------------------------------
4745 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4746 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4747 _instance_id, add_offset_speculative(offset), _inline_depth);
4748 }
4749
4750 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4751 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4752 _instance_id, with_offset_speculative(offset), _inline_depth);
4753 }
4754
4755 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4756 if (_speculative == nullptr) {
4757 return this;
4758 }
4759 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4760 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4761 _instance_id, nullptr, _inline_depth);
4762 }
4763
4764 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4765 if (!UseInlineDepthForSpeculativeTypes) {
4766 return this;
4767 }
4768 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4769 }
4770
4771 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4772 assert(is_known_instance(), "should be known");
4773 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4774 }
4775
4776 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4777 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4778 }
4779
4780 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4781 bool xk = klass_is_exact();
4782 ciInstanceKlass* ik = klass()->as_instance_klass();
4783 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4784 if (_interfaces->eq(ik)) {
4785 Compile* C = Compile::current();
4786 Dependencies* deps = C->dependencies();
4787 deps->assert_leaf_type(ik);
4788 xk = true;
4789 }
4790 }
4791 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4792 }
4793
4794 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) {
4795 static_assert(std::is_base_of<T2, T1>::value, "");
4796
4797 if (!this_one->is_instance_type(other)) {
4798 return false;
4799 }
4800
4801 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4802 return true;
4803 }
4804
4805 return this_one->klass()->is_subtype_of(other->klass()) &&
4806 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4807 }
4808
4809
4810 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4811 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4816 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4817 return true;
4818 }
4819
4820 if (this_one->is_instance_type(other)) {
4821 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4822 }
4823
4824 int dummy;
4825 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4826 if (this_top_or_bottom) {
4827 return false;
4828 }
4829
4830 const T1* other_ary = this_one->is_array_type(other);
4831 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4832 const TypePtr* this_elem = this_one->elem()->make_ptr();
4833 if (other_elem != nullptr && this_elem != nullptr) {
4834 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4835 }
4836 if (other_elem == nullptr && this_elem == nullptr) {
4837 return this_one->_klass->is_subtype_of(other->_klass);
4838 }
4839
4840 return false;
4841 }
4842
4843 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4844 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4845 }
4846
4847 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4848 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4849 }
4850
4851 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4852 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4853 }
4854
4855 //=============================================================================
4856 // Convenience common pre-built types.
4857 const TypeAryPtr *TypeAryPtr::RANGE;
4858 const TypeAryPtr *TypeAryPtr::OOPS;
4859 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4860 const TypeAryPtr *TypeAryPtr::BYTES;
4861 const TypeAryPtr *TypeAryPtr::SHORTS;
4862 const TypeAryPtr *TypeAryPtr::CHARS;
4863 const TypeAryPtr *TypeAryPtr::INTS;
4864 const TypeAryPtr *TypeAryPtr::LONGS;
4865 const TypeAryPtr *TypeAryPtr::FLOATS;
4866 const TypeAryPtr *TypeAryPtr::DOUBLES;
4867 const TypeAryPtr *TypeAryPtr::INLINES;
4868
4869 //------------------------------make-------------------------------------------
4870 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4871 int instance_id, const TypePtr* speculative, int inline_depth) {
4872 assert(!(k == nullptr && ary->_elem->isa_int()),
4873 "integral arrays must be pre-equipped with a class");
4874 if (!xk) xk = ary->ary_must_be_exact();
4875 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4876 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4877 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4878 k = nullptr;
4879 }
4880 if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4881 k = nullptr;
4882 }
4883 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4884 }
4885
4886 //------------------------------make-------------------------------------------
4887 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4888 int instance_id, const TypePtr* speculative, int inline_depth,
4889 bool is_autobox_cache) {
4890 assert(!(k == nullptr && ary->_elem->isa_int()),
4891 "integral arrays must be pre-equipped with a class");
4892 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4893 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4894 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4895 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4896 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4897 k = nullptr;
4898 }
4899 if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4900 k = nullptr;
4901 }
4902 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4903 }
4904
4905 //------------------------------cast_to_ptr_type-------------------------------
4906 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4907 if( ptr == _ptr ) return this;
4908 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4909 }
4910
4911
4912 //-----------------------------cast_to_exactness-------------------------------
4913 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4914 if( klass_is_exact == _klass_is_exact ) return this;
4915 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4916 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4917 }
4918
4919 //-----------------------------cast_to_instance_id----------------------------
4920 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4921 if( instance_id == _instance_id ) return this;
4922 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4923 }
4924
4925
4926 //-----------------------------max_array_length-------------------------------
4927 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4928 jint TypeAryPtr::max_array_length(BasicType etype) {
4929 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4930 if (etype == T_NARROWOOP) {
4931 etype = T_OBJECT;
4932 } else if (etype == T_ILLEGAL) { // bottom[]
4933 etype = T_BYTE; // will produce conservatively high value
4934 } else {
4935 fatal("not an element type: %s", type2name(etype));
4936 }
4937 }
4938 return arrayOopDesc::max_array_length(etype);
4939 }
4940
4941 //-----------------------------narrow_size_type-------------------------------
4942 // Narrow the given size type to the index range for the given array base type.
4958 if (hi > max_hi) {
4959 hi = max_hi;
4960 if (size->is_con()) {
4961 lo = hi;
4962 }
4963 chg = true;
4964 }
4965 // Negative length arrays will produce weird intermediate dead fast-path code
4966 if (lo > hi)
4967 return TypeInt::ZERO;
4968 if (!chg)
4969 return size;
4970 return TypeInt::make(lo, hi, Type::WidenMin);
4971 }
4972
4973 //-------------------------------cast_to_size----------------------------------
4974 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4975 assert(new_size != nullptr, "");
4976 new_size = narrow_size_type(new_size);
4977 if (new_size == size()) return this;
4978 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
4979 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4980 }
4981
4982 //-------------------------------cast_to_not_flat------------------------------
4983 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4984 if (not_flat == is_not_flat()) {
4985 return this;
4986 }
4987 assert(!not_flat || !is_flat(), "inconsistency");
4988 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
4989 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4990 // We keep the speculative part if it contains information about flat-/nullability.
4991 // Make sure it's removed if it's not better than the non-speculative type anymore.
4992 if (res->speculative() == res->remove_speculative()) {
4993 return res->remove_speculative();
4994 }
4995 return res;
4996 }
4997
4998 //-------------------------------cast_to_not_null_free-------------------------
4999 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5000 if (not_null_free == is_not_null_free()) {
5001 return this;
5002 }
5003 assert(!not_null_free || !is_flat(), "inconsistency");
5004 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), /* not_flat= */ not_null_free ? true : is_not_flat(), not_null_free);
5005 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5006 _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5007 // We keep the speculative part if it contains information about flat-/nullability.
5008 // Make sure it's removed if it's not better than the non-speculative type anymore.
5009 if (res->speculative() == res->remove_speculative()) {
5010 return res->remove_speculative();
5011 }
5012 return res;
5013 }
5014
5015 //---------------------------------update_properties---------------------------
5016 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5017 if ((from->is_flat() && is_not_flat()) ||
5018 (from->is_not_flat() && is_flat()) ||
5019 (from->is_null_free() && is_not_null_free()) ||
5020 (from->is_not_null_free() && is_null_free())) {
5021 return nullptr; // Inconsistent properties
5022 } else if (from->is_not_null_free()) {
5023 return cast_to_not_null_free(); // Implies not flat
5024 } else if (from->is_not_flat()) {
5025 return cast_to_not_flat();
5026 }
5027 return this;
5028 }
5029
5030 jint TypeAryPtr::flat_layout_helper() const {
5031 return klass()->as_flat_array_klass()->layout_helper();
5032 }
5033
5034 int TypeAryPtr::flat_elem_size() const {
5035 return klass()->as_flat_array_klass()->element_byte_size();
5036 }
5037
5038 int TypeAryPtr::flat_log_elem_size() const {
5039 return klass()->as_flat_array_klass()->log2_element_size();
5040 }
5041
5042 //------------------------------cast_to_stable---------------------------------
5043 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5044 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5045 return this;
5046
5047 const Type* elem = this->elem();
5048 const TypePtr* elem_ptr = elem->make_ptr();
5049
5050 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5051 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5052 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5053 }
5054
5055 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
5056
5057 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5058 }
5059
5060 //-----------------------------stable_dimension--------------------------------
5061 int TypeAryPtr::stable_dimension() const {
5062 if (!is_stable()) return 0;
5063 int dim = 1;
5064 const TypePtr* elem_ptr = elem()->make_ptr();
5065 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5066 dim += elem_ptr->is_aryptr()->stable_dimension();
5067 return dim;
5068 }
5069
5070 //----------------------cast_to_autobox_cache-----------------------------------
5071 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5072 if (is_autobox_cache()) return this;
5073 const TypeOopPtr* etype = elem()->make_oopptr();
5074 if (etype == nullptr) return this;
5075 // The pointers in the autobox arrays are always non-null.
5076 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5077 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5078 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5079 }
5080
5081 //------------------------------eq---------------------------------------------
5082 // Structural equality check for Type representations
5083 bool TypeAryPtr::eq( const Type *t ) const {
5084 const TypeAryPtr *p = t->is_aryptr();
5085 return
5086 _ary == p->_ary && // Check array
5087 TypeOopPtr::eq(p) &&// Check sub-parts
5088 _field_offset == p->_field_offset;
5089 }
5090
5091 //------------------------------hash-------------------------------------------
5092 // Type-specific hashing function.
5093 uint TypeAryPtr::hash(void) const {
5094 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5095 }
5096
5097 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5098 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5099 }
5100
5101 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5102 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5103 }
5104
5105 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5106 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5107 }
5108 //------------------------------meet-------------------------------------------
5109 // Compute the MEET of two types. It returns a new Type object.
5110 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5111 // Perform a fast test for common case; meeting the same types together.
5112 if( this == t ) return this; // Meeting same type-rep?
5113 // Current "this->_base" is Pointer
5114 switch (t->base()) { // switch on original type
5118 case Long:
5119 case FloatTop:
5120 case FloatCon:
5121 case FloatBot:
5122 case DoubleTop:
5123 case DoubleCon:
5124 case DoubleBot:
5125 case NarrowOop:
5126 case NarrowKlass:
5127 case Bottom: // Ye Olde Default
5128 return Type::BOTTOM;
5129 case Top:
5130 return this;
5131
5132 default: // All else is a mistake
5133 typerr(t);
5134
5135 case OopPtr: { // Meeting to OopPtrs
5136 // Found a OopPtr type vs self-AryPtr type
5137 const TypeOopPtr *tp = t->is_oopptr();
5138 Offset offset = meet_offset(tp->offset());
5139 PTR ptr = meet_ptr(tp->ptr());
5140 int depth = meet_inline_depth(tp->inline_depth());
5141 const TypePtr* speculative = xmeet_speculative(tp);
5142 switch (tp->ptr()) {
5143 case TopPTR:
5144 case AnyNull: {
5145 int instance_id = meet_instance_id(InstanceTop);
5146 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5147 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5148 }
5149 case BotPTR:
5150 case NotNull: {
5151 int instance_id = meet_instance_id(tp->instance_id());
5152 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5153 }
5154 default: ShouldNotReachHere();
5155 }
5156 }
5157
5158 case AnyPtr: { // Meeting two AnyPtrs
5159 // Found an AnyPtr type vs self-AryPtr type
5160 const TypePtr *tp = t->is_ptr();
5161 Offset offset = meet_offset(tp->offset());
5162 PTR ptr = meet_ptr(tp->ptr());
5163 const TypePtr* speculative = xmeet_speculative(tp);
5164 int depth = meet_inline_depth(tp->inline_depth());
5165 switch (tp->ptr()) {
5166 case TopPTR:
5167 return this;
5168 case BotPTR:
5169 case NotNull:
5170 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5171 case Null:
5172 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5173 // else fall through to AnyNull
5174 case AnyNull: {
5175 int instance_id = meet_instance_id(InstanceTop);
5176 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5177 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5178 }
5179 default: ShouldNotReachHere();
5180 }
5181 }
5182
5183 case MetadataPtr:
5184 case KlassPtr:
5185 case InstKlassPtr:
5186 case AryKlassPtr:
5187 case RawPtr: return TypePtr::BOTTOM;
5188
5189 case AryPtr: { // Meeting 2 references?
5190 const TypeAryPtr *tap = t->is_aryptr();
5191 Offset off = meet_offset(tap->offset());
5192 Offset field_off = meet_field_offset(tap->field_offset());
5193 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5194 PTR ptr = meet_ptr(tap->ptr());
5195 int instance_id = meet_instance_id(tap->instance_id());
5196 const TypePtr* speculative = xmeet_speculative(tap);
5197 int depth = meet_inline_depth(tap->inline_depth());
5198
5199 ciKlass* res_klass = nullptr;
5200 bool res_xk = false;
5201 bool res_flat = false;
5202 bool res_not_flat = false;
5203 bool res_not_null_free = false;
5204 const Type* elem = tary->_elem;
5205 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5206 instance_id = InstanceBot;
5207 } else if (this->is_flat() != tap->is_flat()) {
5208 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5209 if (tary->_flat) {
5210 // Result is in a flat representation
5211 off = Offset(is_flat() ? offset() : tap->offset());
5212 field_off = is_flat() ? field_offset() : tap->field_offset();
5213 } else if (below_centerline(ptr)) {
5214 // Result is in a non-flat representation
5215 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5216 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5217 } else if (flat_offset() == tap->flat_offset()) {
5218 off = Offset(!is_flat() ? offset() : tap->offset());
5219 field_off = !is_flat() ? field_offset() : tap->field_offset();
5220 }
5221 }
5222
5223 ciObject* o = nullptr; // Assume not constant when done
5224 ciObject* this_oop = const_oop();
5225 ciObject* tap_oop = tap->const_oop();
5226 if (ptr == Constant) {
5227 if (this_oop != nullptr && tap_oop != nullptr &&
5228 this_oop->equals(tap_oop)) {
5229 o = tap_oop;
5230 } else if (above_centerline(_ptr)) {
5231 o = tap_oop;
5232 } else if (above_centerline(tap->_ptr)) {
5233 o = this_oop;
5234 } else {
5235 ptr = NotNull;
5236 }
5237 }
5238 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5239 }
5240
5241 // All arrays inherit from Object class
5242 case InstPtr: {
5243 const TypeInstPtr *tp = t->is_instptr();
5244 Offset offset = meet_offset(tp->offset());
5245 PTR ptr = meet_ptr(tp->ptr());
5246 int instance_id = meet_instance_id(tp->instance_id());
5247 const TypePtr* speculative = xmeet_speculative(tp);
5248 int depth = meet_inline_depth(tp->inline_depth());
5249 const TypeInterfaces* interfaces = meet_interfaces(tp);
5250 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5251 const TypeInterfaces* this_interfaces = _interfaces;
5252
5253 switch (ptr) {
5254 case TopPTR:
5255 case AnyNull: // Fall 'down' to dual of object klass
5256 // For instances when a subclass meets a superclass we fall
5257 // below the centerline when the superclass is exact. We need to
5258 // do the same here.
5259 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5260 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5261 } else {
5262 // cannot subclass, so the meet has to fall badly below the centerline
5263 ptr = NotNull;
5264 instance_id = InstanceBot;
5265 interfaces = this_interfaces->intersection_with(tp_interfaces);
5266 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5267 }
5268 case Constant:
5269 case NotNull:
5270 case BotPTR: // Fall down to object klass
5271 // LCA is object_klass, but if we subclass from the top we can do better
5272 if (above_centerline(tp->ptr())) {
5273 // If 'tp' is above the centerline and it is Object class
5274 // then we can subclass in the Java class hierarchy.
5275 // For instances when a subclass meets a superclass we fall
5276 // below the centerline when the superclass is exact. We need
5277 // to do the same here.
5278 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5279 // that is, my array type is a subtype of 'tp' klass
5280 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5281 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5282 }
5283 }
5284 // The other case cannot happen, since t cannot be a subtype of an array.
5285 // The meet falls down to Object class below centerline.
5286 if (ptr == Constant) {
5287 ptr = NotNull;
5288 }
5289 if (instance_id > 0) {
5290 instance_id = InstanceBot;
5291 }
5292 interfaces = this_interfaces->intersection_with(tp_interfaces);
5293 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5294 default: typerr(t);
5295 }
5296 }
5297 }
5298 return this; // Lint noise
5299 }
5300
5301
5302 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5303 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5304 int dummy;
5305 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5306 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5307 ciKlass* this_klass = this_ary->klass();
5308 ciKlass* other_klass = other_ary->klass();
5309 bool this_xk = this_ary->klass_is_exact();
5310 bool other_xk = other_ary->klass_is_exact();
5311 PTR this_ptr = this_ary->ptr();
5312 PTR other_ptr = other_ary->ptr();
5313 bool this_flat = this_ary->is_flat();
5314 bool this_not_flat = this_ary->is_not_flat();
5315 bool other_flat = other_ary->is_flat();
5316 bool other_not_flat = other_ary->is_not_flat();
5317 bool this_not_null_free = this_ary->is_not_null_free();
5318 bool other_not_null_free = other_ary->is_not_null_free();
5319 res_klass = nullptr;
5320 MeetResult result = SUBTYPE;
5321 res_flat = this_flat && other_flat;
5322 res_not_flat = this_not_flat && other_not_flat;
5323 res_not_null_free = this_not_null_free && other_not_null_free;
5324
5325 if (elem->isa_int()) {
5326 // Integral array element types have irrelevant lattice relations.
5327 // It is the klass that determines array layout, not the element type.
5328 if (this_top_or_bottom) {
5329 res_klass = other_klass;
5330 } else if (other_top_or_bottom || other_klass == this_klass) {
5331 res_klass = this_klass;
5332 } else {
5333 // Something like byte[int+] meets char[int+].
5334 // This must fall to bottom, not (int[-128..65535])[int+].
5335 // instance_id = InstanceBot;
5336 elem = Type::BOTTOM;
5337 result = NOT_SUBTYPE;
5338 if (above_centerline(ptr) || ptr == Constant) {
5339 ptr = NotNull;
5340 res_xk = false;
5341 return NOT_SUBTYPE;
5342 }
5343 }
5344 } else {// Non integral arrays.
5345 // Must fall to bottom if exact klasses in upper lattice
5346 // are not equal or super klass is exact.
5347 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5348 // meet with top[] and bottom[] are processed further down:
5349 !this_top_or_bottom && !other_top_or_bottom &&
5350 // both are exact and not equal:
5352 // 'tap' is exact and super or unrelated:
5353 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5354 // 'this' is exact and super or unrelated:
5355 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5356 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5357 elem = Type::BOTTOM;
5358 }
5359 ptr = NotNull;
5360 res_xk = false;
5361 return NOT_SUBTYPE;
5362 }
5363 }
5364
5365 res_xk = false;
5366 switch (other_ptr) {
5367 case AnyNull:
5368 case TopPTR:
5369 // Compute new klass on demand, do not use tap->_klass
5370 if (below_centerline(this_ptr)) {
5371 res_xk = this_xk;
5372 if (this_ary->is_flat()) {
5373 elem = this_ary->elem();
5374 }
5375 } else {
5376 res_xk = (other_xk || this_xk);
5377 }
5378 break;
5379 case Constant: {
5380 if (this_ptr == Constant) {
5381 res_xk = true;
5382 } else if (above_centerline(this_ptr)) {
5383 res_xk = true;
5384 } else {
5385 // Only precise for identical arrays
5386 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5387 // TODO 8325106 Fix comment
5388 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5389 if (res_xk && !res_not_null_free) {
5390 res_xk = false;
5391 }
5392 }
5393 break;
5394 }
5395 case NotNull:
5396 case BotPTR:
5397 // Compute new klass on demand, do not use tap->_klass
5398 if (above_centerline(this_ptr)) {
5399 res_xk = other_xk;
5400 if (other_ary->is_flat()) {
5401 elem = other_ary->elem();
5402 }
5403 } else {
5404 res_xk = (other_xk && this_xk) &&
5405 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5406 // TODO 8325106 Fix comment
5407 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5408 if (res_xk && !res_not_null_free) {
5409 res_xk = false;
5410 }
5411 }
5412 break;
5413 default: {
5414 ShouldNotReachHere();
5415 return result;
5416 }
5417 }
5418 return result;
5419 }
5420
5421
5422 //------------------------------xdual------------------------------------------
5423 // Dual: compute field-by-field dual
5424 const Type *TypeAryPtr::xdual() const {
5425 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, _klass_is_exact, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5426 }
5427
5428 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5429 return _field_offset.meet(offset);
5430 }
5431
5432 //------------------------------dual_offset------------------------------------
5433 Type::Offset TypeAryPtr::dual_field_offset() const {
5434 return _field_offset.dual();
5435 }
5436
5437 //------------------------------dump2------------------------------------------
5438 #ifndef PRODUCT
5439 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5440 _ary->dump2(d,depth,st);
5441 _interfaces->dump(st);
5442
5443 switch( _ptr ) {
5444 case Constant:
5445 const_oop()->print(st);
5446 break;
5447 case BotPTR:
5448 if (!WizardMode && !Verbose) {
5449 if( _klass_is_exact ) st->print(":exact");
5450 break;
5451 }
5452 case TopPTR:
5453 case AnyNull:
5454 case NotNull:
5455 st->print(":%s", ptr_msg[_ptr]);
5456 if( _klass_is_exact ) st->print(":exact");
5457 break;
5458 default:
5459 break;
5460 }
5461
5462 if (is_flat()) {
5463 st->print(":flat");
5464 st->print("(");
5465 _field_offset.dump2(st);
5466 st->print(")");
5467 }
5468 if (is_null_free()) {
5469 st->print(":null_free");
5470 }
5471 if (offset() != 0) {
5472 int header_size = objArrayOopDesc::header_size() * wordSize;
5473 if( _offset == Offset::top ) st->print("+undefined");
5474 else if( _offset == Offset::bottom ) st->print("+any");
5475 else if( offset() < header_size ) st->print("+%d", offset());
5476 else {
5477 BasicType basic_elem_type = elem()->basic_type();
5478 if (basic_elem_type == T_ILLEGAL) {
5479 st->print("+any");
5480 } else {
5481 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5482 int elem_size = type2aelembytes(basic_elem_type);
5483 st->print("[%d]", (offset() - array_base)/elem_size);
5484 }
5485 }
5486 }
5487 st->print(" *");
5488 if (_instance_id == InstanceTop)
5489 st->print(",iid=top");
5490 else if (_instance_id != InstanceBot)
5491 st->print(",iid=%d",_instance_id);
5492
5493 dump_inline_depth(st);
5494 dump_speculative(st);
5495 }
5496 #endif
5497
5498 bool TypeAryPtr::empty(void) const {
5499 if (_ary->empty()) return true;
5500 // FIXME: Does this belong here? Or in the meet code itself?
5501 if (is_flat() && is_not_flat()) {
5502 return true;
5503 }
5504 return TypeOopPtr::empty();
5505 }
5506
5507 //------------------------------add_offset-------------------------------------
5508 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5509 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);
5510 }
5511
5512 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5513 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);
5514 }
5515
5516 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5517 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5518 }
5519
5520 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5521 if (_speculative == nullptr) {
5522 return this;
5523 }
5524 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5525 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);
5526 }
5527
5528 const Type* TypeAryPtr::cleanup_speculative() const {
5529 if (speculative() == nullptr) {
5530 return this;
5531 }
5532 // Keep speculative part if it contains information about flat-/nullability
5533 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5534 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5535 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5536 return this;
5537 }
5538 return TypeOopPtr::cleanup_speculative();
5539 }
5540
5541 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5542 if (!UseInlineDepthForSpeculativeTypes) {
5543 return this;
5544 }
5545 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5546 }
5547
5548 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5549 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);
5550 }
5551
5552 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5553 int adj = 0;
5554 if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5555 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5556 adj = _offset.get();
5557 offset += _offset.get();
5558 }
5559 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5560 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5561 offset += _field_offset.get();
5562 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5563 offset += header;
5564 }
5565 }
5566 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5567 // Try to get the field of the inline type array element we are pointing to
5568 ciInlineKlass* vk = elem()->inline_klass();
5569 int shift = flat_log_elem_size();
5570 int mask = (1 << shift) - 1;
5571 intptr_t field_offset = ((offset - header) & mask);
5572 ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5573 if (field != nullptr) {
5574 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5575 }
5576 }
5577 }
5578 return add_offset(offset - adj);
5579 }
5580
5581 // Return offset incremented by field_offset for flat inline type arrays
5582 int TypeAryPtr::flat_offset() const {
5583 int offset = _offset.get();
5584 if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5585 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5586 offset += _field_offset.get();
5587 }
5588 return offset;
5589 }
5590
5591 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5592 assert(is_known_instance(), "should be known");
5593 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5594 }
5595
5596 //=============================================================================
5597
5598
5599 //------------------------------hash-------------------------------------------
5600 // Type-specific hashing function.
5601 uint TypeNarrowPtr::hash(void) const {
5602 return _ptrtype->hash() + 7;
5603 }
5604
5605 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5606 return _ptrtype->singleton();
5607 }
5608
5609 bool TypeNarrowPtr::empty(void) const {
5610 return _ptrtype->empty();
5611 }
5612
5613 intptr_t TypeNarrowPtr::get_con() const {
5614 return _ptrtype->get_con();
5615 }
5616
5617 bool TypeNarrowPtr::eq( const Type *t ) const {
5618 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5669
5670 case Int: // Mixing ints & oops happens when javac
5671 case Long: // reuses local variables
5672 case FloatTop:
5673 case FloatCon:
5674 case FloatBot:
5675 case DoubleTop:
5676 case DoubleCon:
5677 case DoubleBot:
5678 case AnyPtr:
5679 case RawPtr:
5680 case OopPtr:
5681 case InstPtr:
5682 case AryPtr:
5683 case MetadataPtr:
5684 case KlassPtr:
5685 case InstKlassPtr:
5686 case AryKlassPtr:
5687 case NarrowOop:
5688 case NarrowKlass:
5689 case Bottom: // Ye Olde Default
5690 return Type::BOTTOM;
5691 case Top:
5692 return this;
5693
5694 default: // All else is a mistake
5695 typerr(t);
5696
5697 } // End of switch
5698
5699 return this;
5700 }
5701
5702 #ifndef PRODUCT
5703 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5704 _ptrtype->dump2(d, depth, st);
5705 }
5706 #endif
5707
5708 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5752 return (one == two) && TypePtr::eq(t);
5753 } else {
5754 return one->equals(two) && TypePtr::eq(t);
5755 }
5756 }
5757
5758 //------------------------------hash-------------------------------------------
5759 // Type-specific hashing function.
5760 uint TypeMetadataPtr::hash(void) const {
5761 return
5762 (metadata() ? metadata()->hash() : 0) +
5763 TypePtr::hash();
5764 }
5765
5766 //------------------------------singleton--------------------------------------
5767 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5768 // constants
5769 bool TypeMetadataPtr::singleton(void) const {
5770 // detune optimizer to not generate constant metadata + constant offset as a constant!
5771 // TopPTR, Null, AnyNull, Constant are all singletons
5772 return (offset() == 0) && !below_centerline(_ptr);
5773 }
5774
5775 //------------------------------add_offset-------------------------------------
5776 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5777 return make( _ptr, _metadata, xadd_offset(offset));
5778 }
5779
5780 //-----------------------------filter------------------------------------------
5781 // Do not allow interface-vs.-noninterface joins to collapse to top.
5782 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5783 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5784 if (ft == nullptr || ft->empty())
5785 return Type::TOP; // Canonical empty value
5786 return ft;
5787 }
5788
5789 //------------------------------get_con----------------------------------------
5790 intptr_t TypeMetadataPtr::get_con() const {
5791 assert( _ptr == Null || _ptr == Constant, "" );
5792 assert(offset() >= 0, "");
5793
5794 if (offset() != 0) {
5795 // After being ported to the compiler interface, the compiler no longer
5796 // directly manipulates the addresses of oops. Rather, it only has a pointer
5797 // to a handle at compile time. This handle is embedded in the generated
5798 // code and dereferenced at the time the nmethod is made. Until that time,
5799 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5800 // have access to the addresses!). This does not seem to currently happen,
5801 // but this assertion here is to help prevent its occurrence.
5802 tty->print_cr("Found oop constant with non-zero offset");
5803 ShouldNotReachHere();
5804 }
5805
5806 return (intptr_t)metadata()->constant_encoding();
5807 }
5808
5809 //------------------------------cast_to_ptr_type-------------------------------
5810 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5811 if( ptr == _ptr ) return this;
5812 return make(ptr, metadata(), _offset);
5813 }
5814
5825 case Long: // reuses local variables
5826 case FloatTop:
5827 case FloatCon:
5828 case FloatBot:
5829 case DoubleTop:
5830 case DoubleCon:
5831 case DoubleBot:
5832 case NarrowOop:
5833 case NarrowKlass:
5834 case Bottom: // Ye Olde Default
5835 return Type::BOTTOM;
5836 case Top:
5837 return this;
5838
5839 default: // All else is a mistake
5840 typerr(t);
5841
5842 case AnyPtr: {
5843 // Found an AnyPtr type vs self-OopPtr type
5844 const TypePtr *tp = t->is_ptr();
5845 Offset offset = meet_offset(tp->offset());
5846 PTR ptr = meet_ptr(tp->ptr());
5847 switch (tp->ptr()) {
5848 case Null:
5849 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5850 // else fall through:
5851 case TopPTR:
5852 case AnyNull: {
5853 return make(ptr, _metadata, offset);
5854 }
5855 case BotPTR:
5856 case NotNull:
5857 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5858 default: typerr(t);
5859 }
5860 }
5861
5862 case RawPtr:
5863 case KlassPtr:
5864 case InstKlassPtr:
5865 case AryKlassPtr:
5866 case OopPtr:
5867 case InstPtr:
5868 case AryPtr:
5869 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5870
5871 case MetadataPtr: {
5872 const TypeMetadataPtr *tp = t->is_metadataptr();
5873 Offset offset = meet_offset(tp->offset());
5874 PTR tptr = tp->ptr();
5875 PTR ptr = meet_ptr(tptr);
5876 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5877 if (tptr == TopPTR || _ptr == TopPTR ||
5878 metadata()->equals(tp->metadata())) {
5879 return make(ptr, md, offset);
5880 }
5881 // metadata is different
5882 if( ptr == Constant ) { // Cannot be equal constants, so...
5883 if( tptr == Constant && _ptr != Constant) return t;
5884 if( _ptr == Constant && tptr != Constant) return this;
5885 ptr = NotNull; // Fall down in lattice
5886 }
5887 return make(ptr, nullptr, offset);
5888 break;
5889 }
5890 } // End of switch
5891 return this; // Return the double constant
5892 }
5893
5894
5895 //------------------------------xdual------------------------------------------
5896 // Dual of a pure metadata pointer.
5897 const Type *TypeMetadataPtr::xdual() const {
5898 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5899 }
5900
5901 //------------------------------dump2------------------------------------------
5902 #ifndef PRODUCT
5903 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5904 st->print("metadataptr:%s", ptr_msg[_ptr]);
5905 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5906 switch (offset()) {
5907 case OffsetTop: st->print("+top"); break;
5908 case OffsetBot: st->print("+any"); break;
5909 case 0: break;
5910 default: st->print("+%d",offset()); break;
5911 }
5912 }
5913 #endif
5914
5915
5916 //=============================================================================
5917 // Convenience common pre-built type.
5918 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5919
5920 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5921 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5922 }
5923
5924 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5925 return make(Constant, m, Offset(0));
5926 }
5927 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5928 return make(Constant, m, Offset(0));
5929 }
5930
5931 //------------------------------make-------------------------------------------
5932 // Create a meta data constant
5933 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5934 assert(m == nullptr || !m->is_klass(), "wrong type");
5935 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5936 }
5937
5938
5939 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5940 const Type* elem = _ary->_elem;
5941 bool xk = klass_is_exact();
5942 if (elem->make_oopptr() != nullptr) {
5943 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5944 if (elem->is_klassptr()->klass_is_exact() &&
5945 // TODO 8325106 Fix comment
5946 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5947 (is_null_free() || is_flat() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5948 xk = true;
5949 }
5950 }
5951 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5952 }
5953
5954 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5955 if (klass->is_instance_klass()) {
5956 return TypeInstKlassPtr::make(klass, interface_handling);
5957 }
5958 return TypeAryKlassPtr::make(klass, interface_handling);
5959 }
5960
5961 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
5962 if (klass->is_instance_klass()) {
5963 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5964 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5965 }
5966 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5967 }
5968
5969 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
5970 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5971 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5972 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5973 }
5974
5975 // Is there a single ciKlass* that can represent that type?
5976 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5977 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5978 if (_interfaces->empty()) {
5979 return _klass;
5980 }
5981 if (_klass != ciEnv::current()->Object_klass()) {
5982 if (_interfaces->eq(_klass->as_instance_klass())) {
5983 return _klass;
5984 }
5985 return nullptr;
5986 }
5987 return _interfaces->exact_klass();
5988 }
5989
5990 //------------------------------eq---------------------------------------------
5991 // Structural equality check for Type representations
5992 bool TypeKlassPtr::eq(const Type *t) const {
5993 const TypeKlassPtr *p = t->is_klassptr();
5994 return
5995 _interfaces->eq(p->_interfaces) &&
5996 TypePtr::eq(p);
5997 }
5998
5999 //------------------------------hash-------------------------------------------
6000 // Type-specific hashing function.
6001 uint TypeKlassPtr::hash(void) const {
6002 return TypePtr::hash() + _interfaces->hash();
6003 }
6004
6005 //------------------------------singleton--------------------------------------
6006 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6007 // constants
6008 bool TypeKlassPtr::singleton(void) const {
6009 // detune optimizer to not generate constant klass + constant offset as a constant!
6010 // TopPTR, Null, AnyNull, Constant are all singletons
6011 return (offset() == 0) && !below_centerline(_ptr);
6012 }
6013
6014 // Do not allow interface-vs.-noninterface joins to collapse to top.
6015 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6016 // logic here mirrors the one from TypeOopPtr::filter. See comments
6017 // there.
6018 const Type* ft = join_helper(kills, include_speculative);
6019 const TypeKlassPtr* ftkp = ft->isa_instklassptr();
6020 const TypeKlassPtr* ktkp = kills->isa_instklassptr();
6021
6022 if (ft->empty()) {
6023 return Type::TOP; // Canonical empty value
6024 }
6025
6026 return ft;
6027 }
6028
6029 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6030 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6031 return _interfaces->union_with(other->_interfaces);
6032 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6033 return other->_interfaces;
6034 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6035 return _interfaces;
6036 }
6037 return _interfaces->intersection_with(other->_interfaces);
6038 }
6039
6040 //------------------------------get_con----------------------------------------
6041 intptr_t TypeKlassPtr::get_con() const {
6042 assert( _ptr == Null || _ptr == Constant, "" );
6043 assert( offset() >= 0, "" );
6044
6045 if (offset() != 0) {
6046 // After being ported to the compiler interface, the compiler no longer
6047 // directly manipulates the addresses of oops. Rather, it only has a pointer
6048 // to a handle at compile time. This handle is embedded in the generated
6049 // code and dereferenced at the time the nmethod is made. Until that time,
6050 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6051 // have access to the addresses!). This does not seem to currently happen,
6052 // but this assertion here is to help prevent its occurrence.
6053 tty->print_cr("Found oop constant with non-zero offset");
6054 ShouldNotReachHere();
6055 }
6056
6057 ciKlass* k = exact_klass();
6058
6059 return (intptr_t)k->constant_encoding();
6060 }
6061
6062 //------------------------------dump2------------------------------------------
6063 // Dump Klass Type
6064 #ifndef PRODUCT
6065 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
6069 case NotNull:
6070 {
6071 const char *name = klass()->name()->as_utf8();
6072 if (name) {
6073 st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6074 } else {
6075 ShouldNotReachHere();
6076 }
6077 _interfaces->dump(st);
6078 }
6079 case BotPTR:
6080 if (!WizardMode && !Verbose && _ptr != Constant) break;
6081 case TopPTR:
6082 case AnyNull:
6083 st->print(":%s", ptr_msg[_ptr]);
6084 if (_ptr == Constant) st->print(":exact");
6085 break;
6086 default:
6087 break;
6088 }
6089 if (Verbose) {
6090 if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");
6091 }
6092 _offset.dump2(st);
6093 st->print(" *");
6094 }
6095 #endif
6096
6097 //=============================================================================
6098 // Convenience common pre-built types.
6099
6100 // Not-null object klass or below
6101 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6102 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6103
6104 bool TypeInstKlassPtr::eq(const Type *t) const {
6105 const TypeKlassPtr *p = t->is_klassptr();
6106 return
6107 klass()->equals(p->klass()) &&
6108 flat_in_array() == p->flat_in_array() &&
6109 TypeKlassPtr::eq(p);
6110 }
6111
6112 uint TypeInstKlassPtr::hash(void) const {
6113 return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6114 }
6115
6116 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6117 flat_in_array = flat_in_array || k->flat_in_array();
6118
6119 TypeInstKlassPtr *r =
6120 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6121
6122 return r;
6123 }
6124
6125 //------------------------------add_offset-------------------------------------
6126 // Access internals of klass object
6127 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6128 return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6129 }
6130
6131 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6132 return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6133 }
6134
6135 //------------------------------cast_to_ptr_type-------------------------------
6136 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6137 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6138 if( ptr == _ptr ) return this;
6139 return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6140 }
6141
6142
6143 bool TypeInstKlassPtr::must_be_exact() const {
6144 if (!_klass->is_loaded()) return false;
6145 ciInstanceKlass* ik = _klass->as_instance_klass();
6146 if (ik->is_final()) return true; // cannot clear xk
6147 return false;
6148 }
6149
6150 //-----------------------------cast_to_exactness-------------------------------
6151 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6152 if (klass_is_exact == (_ptr == Constant)) return this;
6153 if (must_be_exact()) return this;
6154 ciKlass* k = klass();
6155 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6156 }
6157
6158
6159 //-----------------------------as_instance_type--------------------------------
6160 // Corresponding type for an instance of the given class.
6161 // It will be NotNull, and exact if and only if the klass type is exact.
6162 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6163 ciKlass* k = klass();
6164 bool xk = klass_is_exact();
6165 Compile* C = Compile::current();
6166 Dependencies* deps = C->dependencies();
6167 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6168 // Element is an instance
6169 bool klass_is_exact = false;
6170 const TypeInterfaces* interfaces = _interfaces;
6171 if (k->is_loaded()) {
6172 // Try to set klass_is_exact.
6173 ciInstanceKlass* ik = k->as_instance_klass();
6174 klass_is_exact = ik->is_final();
6175 if (!klass_is_exact && klass_change
6176 && deps != nullptr && UseUniqueSubclasses) {
6177 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6178 if (sub != nullptr) {
6179 if (_interfaces->eq(sub)) {
6180 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6181 k = ik = sub;
6182 xk = sub->is_final();
6183 }
6184 }
6185 }
6186 }
6187 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6188 }
6189
6190 //------------------------------xmeet------------------------------------------
6191 // Compute the MEET of two types, return a new Type object.
6192 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6193 // Perform a fast test for common case; meeting the same types together.
6194 if( this == t ) return this; // Meeting same type-rep?
6195
6196 // Current "this->_base" is Pointer
6197 switch (t->base()) { // switch on original type
6198
6199 case Int: // Mixing ints & oops happens when javac
6200 case Long: // reuses local variables
6201 case FloatTop:
6202 case FloatCon:
6203 case FloatBot:
6204 case DoubleTop:
6205 case DoubleCon:
6206 case DoubleBot:
6207 case NarrowOop:
6208 case NarrowKlass:
6209 case Bottom: // Ye Olde Default
6210 return Type::BOTTOM;
6211 case Top:
6212 return this;
6213
6214 default: // All else is a mistake
6215 typerr(t);
6216
6217 case AnyPtr: { // Meeting to AnyPtrs
6218 // Found an AnyPtr type vs self-KlassPtr type
6219 const TypePtr *tp = t->is_ptr();
6220 Offset offset = meet_offset(tp->offset());
6221 PTR ptr = meet_ptr(tp->ptr());
6222 switch (tp->ptr()) {
6223 case TopPTR:
6224 return this;
6225 case Null:
6226 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6227 case AnyNull:
6228 return make(ptr, klass(), _interfaces, offset, flat_in_array());
6229 case BotPTR:
6230 case NotNull:
6231 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6232 default: typerr(t);
6233 }
6234 }
6235
6236 case RawPtr:
6237 case MetadataPtr:
6238 case OopPtr:
6239 case AryPtr: // Meet with AryPtr
6240 case InstPtr: // Meet with InstPtr
6241 return TypePtr::BOTTOM;
6242
6243 //
6244 // A-top }
6245 // / | \ } Tops
6246 // B-top A-any C-top }
6247 // | / | \ | } Any-nulls
6248 // B-any | C-any }
6249 // | | |
6250 // B-con A-con C-con } constants; not comparable across classes
6251 // | | |
6252 // B-not | C-not }
6253 // | \ | / | } not-nulls
6254 // B-bot A-not C-bot }
6255 // \ | / } Bottoms
6256 // A-bot }
6257 //
6258
6259 case InstKlassPtr: { // Meet two KlassPtr types
6260 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6261 Offset off = meet_offset(tkls->offset());
6262 PTR ptr = meet_ptr(tkls->ptr());
6263 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6264
6265 ciKlass* res_klass = nullptr;
6266 bool res_xk = false;
6267 bool res_flat_in_array = false;
6268 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6269 case UNLOADED:
6270 ShouldNotReachHere();
6271 case SUBTYPE:
6272 case NOT_SUBTYPE:
6273 case LCA:
6274 case QUICK: {
6275 assert(res_xk == (ptr == Constant), "");
6276 const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6277 return res;
6278 }
6279 default:
6280 ShouldNotReachHere();
6281 }
6282 } // End of case KlassPtr
6283 case AryKlassPtr: { // All arrays inherit from Object class
6284 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6285 Offset offset = meet_offset(tp->offset());
6286 PTR ptr = meet_ptr(tp->ptr());
6287 const TypeInterfaces* interfaces = meet_interfaces(tp);
6288 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6289 const TypeInterfaces* this_interfaces = _interfaces;
6290
6291 switch (ptr) {
6292 case TopPTR:
6293 case AnyNull: // Fall 'down' to dual of object klass
6294 // For instances when a subclass meets a superclass we fall
6295 // below the centerline when the superclass is exact. We need to
6296 // do the same here.
6297 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6298 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6299 } else {
6300 // cannot subclass, so the meet has to fall badly below the centerline
6301 ptr = NotNull;
6302 interfaces = _interfaces->intersection_with(tp->_interfaces);
6303 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6304 }
6305 case Constant:
6306 case NotNull:
6307 case BotPTR: // Fall down to object klass
6308 // LCA is object_klass, but if we subclass from the top we can do better
6309 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6310 // If 'this' (InstPtr) is above the centerline and it is Object class
6311 // then we can subclass in the Java class hierarchy.
6312 // For instances when a subclass meets a superclass we fall
6313 // below the centerline when the superclass is exact. We need
6314 // to do the same here.
6315 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6316 // that is, tp's array type is a subtype of my klass
6317 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6318 }
6319 }
6320 // The other case cannot happen, since I cannot be a subtype of an array.
6321 // The meet falls down to Object class below centerline.
6322 if( ptr == Constant )
6323 ptr = NotNull;
6324 interfaces = this_interfaces->intersection_with(tp_interfaces);
6325 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6326 default: typerr(t);
6327 }
6328 }
6329
6330 } // End of switch
6331 return this; // Return the double constant
6332 }
6333
6334 //------------------------------xdual------------------------------------------
6335 // Dual: compute field-by-field dual
6336 const Type *TypeInstKlassPtr::xdual() const {
6337 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6338 }
6339
6340 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) {
6341 static_assert(std::is_base_of<T2, T1>::value, "");
6342 if (!this_one->is_loaded() || !other->is_loaded()) {
6343 return false;
6344 }
6345 if (!this_one->is_instance_type(other)) {
6346 return false;
6347 }
6348
6349 if (!other_exact) {
6350 return false;
6351 }
6352
6353 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6354 return true;
6355 }
6356
6357 return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces->contains(other->_interfaces);
6418 const TypeInterfaces* interfaces = _interfaces;
6419 if (k->is_loaded()) {
6420 ciInstanceKlass* ik = k->as_instance_klass();
6421 bool klass_is_exact = ik->is_final();
6422 if (!klass_is_exact &&
6423 deps != nullptr) {
6424 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6425 if (sub != nullptr) {
6426 if (_interfaces->eq(sub)) {
6427 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6428 k = ik = sub;
6429 klass_is_exact = sub->is_final();
6430 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6431 }
6432 }
6433 }
6434 }
6435 return this;
6436 }
6437
6438 bool TypeInstKlassPtr::can_be_inline_array() const {
6439 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6440 }
6441
6442 bool TypeAryKlassPtr::can_be_inline_array() const {
6443 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6444 }
6445
6446 bool TypeInstPtr::can_be_inline_array() const {
6447 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6448 }
6449
6450 bool TypeAryPtr::can_be_inline_array() const {
6451 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6452 }
6453
6454 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6455 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6456 }
6457
6458 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free) {
6459 if (k->is_obj_array_klass()) {
6460 // Element is an object array. Recursively call ourself.
6461 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6462 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6463 // TODO 8325106 Fix comment
6464 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6465 if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
6466 etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()));
6467 }
6468 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, null_free);
6469 } else if (k->is_type_array_klass()) {
6470 // Element is an typeArray
6471 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6472 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6473 } else if (k->is_flat_array_klass()) {
6474 ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6475 const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6476 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6477 } else {
6478 ShouldNotReachHere();
6479 return nullptr;
6480 }
6481 }
6482
6483 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6484 // TODO 8325106 remove?
6485 bool null_free = k->as_array_klass()->is_elem_null_free();
6486 bool not_null_free = (ptr == Constant) ? !null_free : !k->is_flat_array_klass() && (k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false));
6487
6488 bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != nullptr &&
6489 k->as_array_klass()->element_klass()->is_inlinetype() &&
6490 !k->as_array_klass()->element_klass()->flat_in_array());
6491
6492 return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, null_free);
6493 }
6494
6495 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6496 return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6497 }
6498
6499 //------------------------------eq---------------------------------------------
6500 // Structural equality check for Type representations
6501 bool TypeAryKlassPtr::eq(const Type *t) const {
6502 const TypeAryKlassPtr *p = t->is_aryklassptr();
6503 return
6504 _elem == p->_elem && // Check array
6505 _not_flat == p->_not_flat &&
6506 _not_null_free == p->_not_null_free &&
6507 _null_free == p->_null_free &&
6508 TypeKlassPtr::eq(p); // Check sub-parts
6509 }
6510
6511 //------------------------------hash-------------------------------------------
6512 // Type-specific hashing function.
6513 uint TypeAryKlassPtr::hash(void) const {
6514 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6515 (uint)(_not_null_free ? 44 : 0) + (uint)(_null_free ? 45 : 0);
6516 }
6517
6518 //----------------------compute_klass------------------------------------------
6519 // Compute the defining klass for this class
6520 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6521 // Compute _klass based on element type.
6522 ciKlass* k_ary = nullptr;
6523 const TypeInstPtr *tinst;
6524 const TypeAryPtr *tary;
6525 const Type* el = elem();
6526 if (el->isa_narrowoop()) {
6527 el = el->make_ptr();
6528 }
6529
6530 // Get element klass
6531 if (is_flat() && el->is_inlinetypeptr()) {
6532 // Klass is required by TypeAryPtr::flat_layout_helper() and others
6533 if (el->inline_klass() != nullptr) {
6534 k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6535 }
6536 } else if ((tinst = el->isa_instptr()) != nullptr) {
6537 // Leave k_ary at nullptr.
6538 } else if ((tary = el->isa_aryptr()) != nullptr) {
6539 // Leave k_ary at nullptr.
6540 } else if ((el->base() == Type::Top) ||
6541 (el->base() == Type::Bottom)) {
6542 // element type of Bottom occurs from meet of basic type
6543 // and object; Top occurs when doing join on Bottom.
6544 // Leave k_ary at null.
6545 } else {
6546 // Cannot compute array klass directly from basic type,
6547 // since subtypes of TypeInt all have basic type T_INT.
6548 #ifdef ASSERT
6549 if (verify && el->isa_int()) {
6550 // Check simple cases when verifying klass.
6551 BasicType bt = T_ILLEGAL;
6552 if (el == TypeInt::BYTE) {
6553 bt = T_BYTE;
6554 } else if (el == TypeInt::SHORT) {
6555 bt = T_SHORT;
6556 } else if (el == TypeInt::CHAR) {
6557 bt = T_CHAR;
6558 } else if (el == TypeInt::INT) {
6559 bt = T_INT;
6588 // type TypeAryPtr::OOPS. This Type is shared between all
6589 // active compilations. However, the ciKlass which represents
6590 // this Type is *not* shared between compilations, so caching
6591 // this value would result in fetching a dangling pointer.
6592 //
6593 // Recomputing the underlying ciKlass for each request is
6594 // a bit less efficient than caching, but calls to
6595 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6596 ((TypeAryPtr*)this)->_klass = k_ary;
6597 }
6598 return k_ary;
6599 }
6600
6601 // Is there a single ciKlass* that can represent that type?
6602 ciKlass* TypeAryPtr::exact_klass_helper() const {
6603 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6604 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6605 if (k == nullptr) {
6606 return nullptr;
6607 }
6608 k = ciArrayKlass::make(k, is_null_free());
6609 return k;
6610 }
6611
6612 return klass();
6613 }
6614
6615 const Type* TypeAryPtr::base_element_type(int& dims) const {
6616 const Type* elem = this->elem();
6617 dims = 1;
6618 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6619 elem = elem->make_ptr()->is_aryptr()->elem();
6620 dims++;
6621 }
6622 return elem;
6623 }
6624
6625 //------------------------------add_offset-------------------------------------
6626 // Access internals of klass object
6627 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6628 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6629 }
6630
6631 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6632 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6633 }
6634
6635 //------------------------------cast_to_ptr_type-------------------------------
6636 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6637 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6638 if (ptr == _ptr) return this;
6639 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6640 }
6641
6642 bool TypeAryKlassPtr::must_be_exact() const {
6643 if (_elem == Type::BOTTOM) return false;
6644 if (_elem == Type::TOP ) return false;
6645 const TypeKlassPtr* tk = _elem->isa_klassptr();
6646 if (!tk) return true; // a primitive type, like int
6647 // TODO 8325106 Fix comment
6648 // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6649 if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6650 return false;
6651 }
6652 return tk->must_be_exact();
6653 }
6654
6655
6656 //-----------------------------cast_to_exactness-------------------------------
6657 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6658 if (must_be_exact() && !klass_is_exact) return this; // cannot clear xk
6659 if (klass_is_exact == this->klass_is_exact()) {
6660 return this;
6661 }
6662 ciKlass* k = _klass;
6663 const Type* elem = this->elem();
6664 if (elem->isa_klassptr() && !klass_is_exact) {
6665 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6666 }
6667 bool not_flat = is_not_flat();
6668 bool not_null_free = is_not_null_free();
6669 if (_elem->isa_klassptr()) {
6670 if (klass_is_exact || _elem->isa_aryklassptr()) {
6671 assert(!is_null_free() && !is_flat(), "null-free (or flat) inline type arrays should always be exact");
6672 // An array can't be null-free (or flat) if the klass is exact
6673 not_null_free = true;
6674 not_flat = true;
6675 } else {
6676 // Klass is not exact (anymore), re-compute null-free/flat properties
6677 const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6678 not_null_free = !exact_etype->can_be_inline_type();
6679 not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
6680 }
6681 }
6682 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6683 }
6684
6685 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_null_free() const {
6686 return make(_ptr, elem(), klass(), _offset, is_not_flat(), false, true);
6687 }
6688
6689 //-----------------------------as_instance_type--------------------------------
6690 // Corresponding type for an instance of the given class.
6691 // It will be NotNull, and exact if and only if the klass type is exact.
6692 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6693 ciKlass* k = klass();
6694 bool xk = klass_is_exact();
6695 const Type* el = nullptr;
6696 if (elem()->isa_klassptr()) {
6697 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6698 k = nullptr;
6699 } else {
6700 el = elem();
6701 }
6702 bool null_free = _null_free;
6703 if (null_free && el->isa_ptr()) {
6704 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6705 }
6706 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
6707 }
6708
6709
6710 //------------------------------xmeet------------------------------------------
6711 // Compute the MEET of two types, return a new Type object.
6712 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6713 // Perform a fast test for common case; meeting the same types together.
6714 if( this == t ) return this; // Meeting same type-rep?
6715
6716 // Current "this->_base" is Pointer
6717 switch (t->base()) { // switch on original type
6718
6719 case Int: // Mixing ints & oops happens when javac
6720 case Long: // reuses local variables
6721 case FloatTop:
6722 case FloatCon:
6723 case FloatBot:
6724 case DoubleTop:
6725 case DoubleCon:
6726 case DoubleBot:
6727 case NarrowOop:
6728 case NarrowKlass:
6729 case Bottom: // Ye Olde Default
6730 return Type::BOTTOM;
6731 case Top:
6732 return this;
6733
6734 default: // All else is a mistake
6735 typerr(t);
6736
6737 case AnyPtr: { // Meeting to AnyPtrs
6738 // Found an AnyPtr type vs self-KlassPtr type
6739 const TypePtr *tp = t->is_ptr();
6740 Offset offset = meet_offset(tp->offset());
6741 PTR ptr = meet_ptr(tp->ptr());
6742 switch (tp->ptr()) {
6743 case TopPTR:
6744 return this;
6745 case Null:
6746 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6747 case AnyNull:
6748 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_null_free());
6749 case BotPTR:
6750 case NotNull:
6751 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6752 default: typerr(t);
6753 }
6754 }
6755
6756 case RawPtr:
6757 case MetadataPtr:
6758 case OopPtr:
6759 case AryPtr: // Meet with AryPtr
6760 case InstPtr: // Meet with InstPtr
6761 return TypePtr::BOTTOM;
6762
6763 //
6764 // A-top }
6765 // / | \ } Tops
6766 // B-top A-any C-top }
6767 // | / | \ | } Any-nulls
6768 // B-any | C-any }
6769 // | | |
6770 // B-con A-con C-con } constants; not comparable across classes
6771 // | | |
6772 // B-not | C-not }
6773 // | \ | / | } not-nulls
6774 // B-bot A-not C-bot }
6775 // \ | / } Bottoms
6776 // A-bot }
6777 //
6778
6779 case AryKlassPtr: { // Meet two KlassPtr types
6780 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6781 Offset off = meet_offset(tap->offset());
6782 const Type* elem = _elem->meet(tap->_elem);
6783 PTR ptr = meet_ptr(tap->ptr());
6784 ciKlass* res_klass = nullptr;
6785 bool res_xk = false;
6786 bool res_flat = false;
6787 bool res_not_flat = false;
6788 bool res_not_null_free = false;
6789 MeetResult res = meet_aryptr(ptr, elem, this, tap,
6790 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
6791 assert(res_xk == (ptr == Constant), "");
6792 bool null_free = meet_null_free(tap->_null_free);
6793 if (res == NOT_SUBTYPE) {
6794 null_free = false;
6795 } else if (res == SUBTYPE) {
6796 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6797 null_free = _null_free;
6798 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6799 null_free = tap->_null_free;
6800 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6801 null_free = _null_free || tap->_null_free;
6802 }
6803 }
6804 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6805 } // End of case KlassPtr
6806 case InstKlassPtr: {
6807 const TypeInstKlassPtr *tp = t->is_instklassptr();
6808 Offset offset = meet_offset(tp->offset());
6809 PTR ptr = meet_ptr(tp->ptr());
6810 const TypeInterfaces* interfaces = meet_interfaces(tp);
6811 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6812 const TypeInterfaces* this_interfaces = _interfaces;
6813
6814 switch (ptr) {
6815 case TopPTR:
6816 case AnyNull: // Fall 'down' to dual of object klass
6817 // For instances when a subclass meets a superclass we fall
6818 // below the centerline when the superclass is exact. We need to
6819 // do the same here.
6820 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6821 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6822 } else {
6823 // cannot subclass, so the meet has to fall badly below the centerline
6824 ptr = NotNull;
6825 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6826 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6827 }
6828 case Constant:
6829 case NotNull:
6830 case BotPTR: // Fall down to object klass
6831 // LCA is object_klass, but if we subclass from the top we can do better
6832 if (above_centerline(tp->ptr())) {
6833 // If 'tp' is above the centerline and it is Object class
6834 // then we can subclass in the Java class hierarchy.
6835 // For instances when a subclass meets a superclass we fall
6836 // below the centerline when the superclass is exact. We need
6837 // to do the same here.
6838 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6839 // that is, my array type is a subtype of 'tp' klass
6840 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6841 }
6842 }
6843 // The other case cannot happen, since t cannot be a subtype of an array.
6844 // The meet falls down to Object class below centerline.
6845 if (ptr == Constant)
6846 ptr = NotNull;
6847 interfaces = this_interfaces->intersection_with(tp_interfaces);
6848 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6849 default: typerr(t);
6850 }
6851 }
6852
6853 } // End of switch
6854 return this; // Return the double constant
6855 }
6856
6857 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) {
6858 static_assert(std::is_base_of<T2, T1>::value, "");
6859
6860 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6861 return true;
6862 }
6863
6864 int dummy;
6865 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6866
6867 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6868 return false;
6869 }
6870
6871 if (this_one->is_instance_type(other)) {
6872 return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->intersection_with(this_one->_interfaces)->eq(other->_interfaces) && other_exact;
6873 }
6874
6875 assert(this_one->is_array_type(other), "");
6876 const T1* other_ary = this_one->is_array_type(other);
6877 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6878 if (other_top_or_bottom) {
6879 return false;
6880 }
6881
6882 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6883 const TypePtr* this_elem = this_one->elem()->make_ptr();
6884 if (this_elem != nullptr && other_elem != nullptr) {
6885 if (other->is_null_free() && !this_one->is_null_free()) {
6886 // TODO 8325106 Fix comment
6887 return false; // [LMyValue is not a subtype of [QMyValue
6888 }
6889 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6890 }
6891 if (this_elem == nullptr && other_elem == nullptr) {
6892 return this_one->_klass->is_subtype_of(other->_klass);
6893 }
6894 return false;
6895 }
6896
6897 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6898 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6899 }
6900
6901 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6902 static_assert(std::is_base_of<T2, T1>::value, "");
6903
6904 int dummy;
6905 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6906
6907 if (!this_one->is_array_type(other) ||
6908 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6956 }
6957
6958 const TypePtr* this_elem = this_one->elem()->make_ptr();
6959 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6960 if (other_elem != nullptr && this_elem != nullptr) {
6961 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6962 }
6963 if (other_elem == nullptr && this_elem == nullptr) {
6964 return this_one->_klass->is_subtype_of(other->_klass);
6965 }
6966 return false;
6967 }
6968
6969 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6970 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6971 }
6972
6973 //------------------------------xdual------------------------------------------
6974 // Dual: compute field-by-field dual
6975 const Type *TypeAryKlassPtr::xdual() const {
6976 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6977 }
6978
6979 // Is there a single ciKlass* that can represent that type?
6980 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6981 if (elem()->isa_klassptr()) {
6982 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6983 if (k == nullptr) {
6984 return nullptr;
6985 }
6986 k = ciArrayKlass::make(k, _null_free);
6987 return k;
6988 }
6989
6990 return klass();
6991 }
6992
6993 ciKlass* TypeAryKlassPtr::klass() const {
6994 if (_klass != nullptr) {
6995 return _klass;
6996 }
6997 ciKlass* k = nullptr;
6998 if (elem()->isa_klassptr()) {
6999 // leave null
7000 } else if ((elem()->base() == Type::Top) ||
7001 (elem()->base() == Type::Bottom)) {
7002 } else {
7003 k = ciTypeArrayKlass::make(elem()->basic_type());
7004 ((TypeAryKlassPtr*)this)->_klass = k;
7005 }
7006 return k;
7013 switch( _ptr ) {
7014 case Constant:
7015 st->print("precise ");
7016 case NotNull:
7017 {
7018 st->print("[");
7019 _elem->dump2(d, depth, st);
7020 _interfaces->dump(st);
7021 st->print(": ");
7022 }
7023 case BotPTR:
7024 if( !WizardMode && !Verbose && _ptr != Constant ) break;
7025 case TopPTR:
7026 case AnyNull:
7027 st->print(":%s", ptr_msg[_ptr]);
7028 if( _ptr == Constant ) st->print(":exact");
7029 break;
7030 default:
7031 break;
7032 }
7033 if (is_flat()) st->print(":flat");
7034 if (_null_free) st->print(":null free");
7035 if (Verbose) {
7036 if (_not_flat) st->print(":not flat");
7037 if (_not_null_free) st->print(":not null free");
7038 }
7039
7040 _offset.dump2(st);
7041
7042 st->print(" *");
7043 }
7044 #endif
7045
7046 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7047 const Type* elem = this->elem();
7048 dims = 1;
7049 while (elem->isa_aryklassptr()) {
7050 elem = elem->is_aryklassptr()->elem();
7051 dims++;
7052 }
7053 return elem;
7054 }
7055
7056 //=============================================================================
7057 // Convenience common pre-built types.
7058
7059 //------------------------------make-------------------------------------------
7060 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7061 const TypeTuple *range_sig, const TypeTuple *range_cc) {
7062 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7063 }
7064
7065 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7066 return make(domain, domain, range, range);
7067 }
7068
7069 //------------------------------osr_domain-----------------------------
7070 const TypeTuple* osr_domain() {
7071 const Type **fields = TypeTuple::fields(2);
7072 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7073 return TypeTuple::make(TypeFunc::Parms+1, fields);
7074 }
7075
7076 //------------------------------make-------------------------------------------
7077 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7078 Compile* C = Compile::current();
7079 const TypeFunc* tf = nullptr;
7080 if (!is_osr_compilation) {
7081 tf = C->last_tf(method); // check cache
7082 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7083 }
7084 // Inline types are not passed/returned by reference, instead each field of
7085 // the inline type is passed/returned as an argument. We maintain two views of
7086 // the argument/return list here: one based on the signature (with an inline
7087 // type argument/return as a single slot), one based on the actual calling
7088 // convention (with an inline type argument/return as a list of its fields).
7089 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7090 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7091 if (method != C->method() && method->get_Method()->mismatch()) {
7092 has_scalar_args = false;
7093 }
7094 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7095 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7096 ciSignature* sig = method->signature();
7097 bool has_scalar_ret = sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7098 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7099 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7100 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7101 if (!is_osr_compilation) {
7102 C->set_last_tf(method, tf); // fill cache
7103 }
7104 return tf;
7105 }
7106
7107 //------------------------------meet-------------------------------------------
7108 // Compute the MEET of two types. It returns a new Type object.
7109 const Type *TypeFunc::xmeet( const Type *t ) const {
7110 // Perform a fast test for common case; meeting the same types together.
7111 if( this == t ) return this; // Meeting same type-rep?
7112
7113 // Current "this->_base" is Func
7114 switch (t->base()) { // switch on original type
7115
7116 case Bottom: // Ye Olde Default
7117 return t;
7118
7119 default: // All else is a mistake
7120 typerr(t);
7121
7122 case Top:
7123 break;
7124 }
7125 return this; // Return the double constant
7126 }
7127
7128 //------------------------------xdual------------------------------------------
7129 // Dual: compute field-by-field dual
7130 const Type *TypeFunc::xdual() const {
7131 return this;
7132 }
7133
7134 //------------------------------eq---------------------------------------------
7135 // Structural equality check for Type representations
7136 bool TypeFunc::eq( const Type *t ) const {
7137 const TypeFunc *a = (const TypeFunc*)t;
7138 return _domain_sig == a->_domain_sig &&
7139 _domain_cc == a->_domain_cc &&
7140 _range_sig == a->_range_sig &&
7141 _range_cc == a->_range_cc;
7142 }
7143
7144 //------------------------------hash-------------------------------------------
7145 // Type-specific hashing function.
7146 uint TypeFunc::hash(void) const {
7147 return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7148 }
7149
7150 //------------------------------dump2------------------------------------------
7151 // Dump Function Type
7152 #ifndef PRODUCT
7153 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7154 if( _range_sig->cnt() <= Parms )
7155 st->print("void");
7156 else {
7157 uint i;
7158 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7159 _range_sig->field_at(i)->dump2(d,depth,st);
7160 st->print("/");
7161 }
7162 _range_sig->field_at(i)->dump2(d,depth,st);
7163 }
7164 st->print(" ");
7165 st->print("( ");
7166 if( !depth || d[this] ) { // Check for recursive dump
7167 st->print("...)");
7168 return;
7169 }
7170 d.Insert((void*)this,(void*)this); // Stop recursion
7171 if (Parms < _domain_sig->cnt())
7172 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7173 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7174 st->print(", ");
7175 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7176 }
7177 st->print(" )");
7178 }
7179 #endif
7180
7181 //------------------------------singleton--------------------------------------
7182 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7183 // constants (Ldi nodes). Singletons are integer, float or double constants
7184 // or a single symbol.
7185 bool TypeFunc::singleton(void) const {
7186 return false; // Never a singleton
7187 }
7188
7189 bool TypeFunc::empty(void) const {
7190 return false; // Never empty
7191 }
7192
7193
7194 BasicType TypeFunc::return_type() const{
7195 if (range_sig()->cnt() == TypeFunc::Parms) {
7196 return T_VOID;
7197 }
7198 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7199 }
|