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