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 #ifndef SHARE_OPTO_TYPE_HPP
26 #define SHARE_OPTO_TYPE_HPP
27
28 #include "opto/adlcVMDeps.hpp"
29 #include "opto/compile.hpp"
30 #include "opto/rangeinference.hpp"
31 #include "runtime/handles.hpp"
32
33 // Portions of code courtesy of Clifford Click
34
35 // Optimization - Graph Style
36
37
38 // This class defines a Type lattice. The lattice is used in the constant
39 // propagation algorithms, and for some type-checking of the iloc code.
40 // Basic types include RSD's (lower bound, upper bound, stride for integers),
41 // float & double precision constants, sets of data-labels and code-labels.
42 // The complete lattice is described below. Subtypes have no relationship to
43 // up or down in the lattice; that is entirely determined by the behavior of
44 // the MEET/JOIN functions.
45
46 class Dict;
47 class Type;
48 class TypeD;
49 class TypeF;
50 class TypeH;
51 class TypeInteger;
127 Memory, // Abstract store
128 HalfFloatTop, // No float value
129 HalfFloatCon, // Floating point constant
130 HalfFloatBot, // Any float value
131 FloatTop, // No float value
132 FloatCon, // Floating point constant
133 FloatBot, // Any float value
134 DoubleTop, // No double value
135 DoubleCon, // Double precision constant
136 DoubleBot, // Any double value
137 Bottom, // Bottom of lattice
138 lastype // Bogus ending type (not in lattice)
139 };
140
141 // Signal values for offsets from a base pointer
142 enum OFFSET_SIGNALS {
143 OffsetTop = -2000000000, // undefined offset
144 OffsetBot = -2000000001 // any possible offset
145 };
146
147 // Min and max WIDEN values.
148 enum WIDEN {
149 WidenMin = 0,
150 WidenMax = 3
151 };
152
153 private:
154 typedef struct {
155 TYPES dual_type;
156 BasicType basic_type;
157 const char* msg;
158 bool isa_oop;
159 uint ideal_reg;
160 } TypeInfo;
161
162 // Dictionary of types shared among compilations.
163 static Dict* _shared_type_dict;
164 static const TypeInfo _type_info[];
165
166 static int uhash( const Type *const t );
327 const TypeInstPtr *isa_instptr() const; // Returns null if not InstPtr
328 const TypeInstPtr *is_instptr() const; // Instance
329 const TypeAryPtr *isa_aryptr() const; // Returns null if not AryPtr
330 const TypeAryPtr *is_aryptr() const; // Array oop
331
332 template <typename TypeClass>
333 const TypeClass* cast() const;
334
335 const TypeMetadataPtr *isa_metadataptr() const; // Returns null if not oop ptr type
336 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer
337 const TypeKlassPtr *isa_klassptr() const; // Returns null if not KlassPtr
338 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
339 const TypeInstKlassPtr *isa_instklassptr() const; // Returns null if not IntKlassPtr
340 const TypeInstKlassPtr *is_instklassptr() const; // assert if not IntKlassPtr
341 const TypeAryKlassPtr *isa_aryklassptr() const; // Returns null if not AryKlassPtr
342 const TypeAryKlassPtr *is_aryklassptr() const; // assert if not AryKlassPtr
343
344 virtual bool is_finite() const; // Has a finite value
345 virtual bool is_nan() const; // Is not a number (NaN)
346
347 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
348 const TypePtr* make_ptr() const;
349
350 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
351 // Asserts if the underlying type is not an oopptr or narrowoop.
352 const TypeOopPtr* make_oopptr() const;
353
354 // Returns this compressed pointer or the equivalent compressed version
355 // of this pointer type.
356 const TypeNarrowOop* make_narrowoop() const;
357
358 // Returns this compressed klass pointer or the equivalent
359 // compressed version of this pointer type.
360 const TypeNarrowKlass* make_narrowklass() const;
361
362 // Special test for register pressure heuristic
363 bool is_floatingpoint() const; // True if Float or Double base type
364
365 // Do you have memory, directly or through a tuple?
366 bool has_memory( ) const;
463 static const Type* get_typeflow_type(ciType* type);
464
465 static const Type* make_from_constant(ciConstant constant,
466 bool require_constant = false,
467 int stable_dimension = 0,
468 bool is_narrow = false,
469 bool is_autobox_cache = false);
470
471 static const Type* make_constant_from_field(ciInstance* holder,
472 int off,
473 bool is_unsigned_load,
474 BasicType loadbt);
475
476 static const Type* make_constant_from_field(ciField* field,
477 ciInstance* holder,
478 BasicType loadbt,
479 bool is_unsigned_load);
480
481 static const Type* make_constant_from_array_element(ciArray* array,
482 int off,
483 int stable_dimension,
484 BasicType loadbt,
485 bool is_unsigned_load);
486
487 // Speculative type helper methods. See TypePtr.
488 virtual const TypePtr* speculative() const { return nullptr; }
489 virtual ciKlass* speculative_type() const { return nullptr; }
490 virtual ciKlass* speculative_type_not_null() const { return nullptr; }
491 virtual bool speculative_maybe_null() const { return true; }
492 virtual bool speculative_always_null() const { return true; }
493 virtual const Type* remove_speculative() const { return this; }
494 virtual const Type* cleanup_speculative() const { return this; }
495 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != nullptr; }
496 virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
497 const Type* maybe_remove_speculative(bool include_speculative) const;
498
499 virtual bool maybe_null() const { return true; }
500 virtual bool is_known_instance() const { return false; }
501
502 private:
955 const Type ** const _fields; // Array of field types
956
957 public:
958 virtual bool eq( const Type *t ) const;
959 virtual uint hash() const; // Type specific hashing
960 virtual bool singleton(void) const; // TRUE if type is a singleton
961 virtual bool empty(void) const; // TRUE if type is vacuous
962
963 // Accessors:
964 uint cnt() const { return _cnt; }
965 const Type* field_at(uint i) const {
966 assert(i < _cnt, "oob");
967 return _fields[i];
968 }
969 void set_field_at(uint i, const Type* t) {
970 assert(i < _cnt, "oob");
971 _fields[i] = t;
972 }
973
974 static const TypeTuple *make( uint cnt, const Type **fields );
975 static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces);
976 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling);
977
978 // Subroutine call type with space allocated for argument types
979 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
980 static const Type **fields( uint arg_cnt );
981
982 virtual const Type *xmeet( const Type *t ) const;
983 virtual const Type *xdual() const; // Compute dual right now.
984 // Convenience common pre-built types.
985 static const TypeTuple *IFBOTH;
986 static const TypeTuple *IFFALSE;
987 static const TypeTuple *IFTRUE;
988 static const TypeTuple *IFNEITHER;
989 static const TypeTuple *LOOPBODY;
990 static const TypeTuple *MEMBAR;
991 static const TypeTuple *STORECONDITIONAL;
992 static const TypeTuple *START_I2C;
993 static const TypeTuple *INT_PAIR;
994 static const TypeTuple *LONG_PAIR;
995 static const TypeTuple *INT_CC_PAIR;
996 static const TypeTuple *LONG_CC_PAIR;
997 #ifndef PRODUCT
998 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
999 #endif
1000 };
1001
1002 //------------------------------TypeAry----------------------------------------
1003 // Class of Array Types
1004 class TypeAry : public Type {
1005 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
1006 _elem(elem), _size(size), _stable(stable) {}
1007 public:
1008 virtual bool eq( const Type *t ) const;
1009 virtual uint hash() const; // Type specific hashing
1010 virtual bool singleton(void) const; // TRUE if type is a singleton
1011 virtual bool empty(void) const; // TRUE if type is vacuous
1012
1013 private:
1014 const Type *_elem; // Element type of array
1015 const TypeInt *_size; // Elements in array
1016 const bool _stable; // Are elements @Stable?
1017 friend class TypeAryPtr;
1018
1019 public:
1020 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
1021
1022 virtual const Type *xmeet( const Type *t ) const;
1023 virtual const Type *xdual() const; // Compute dual right now.
1024 bool ary_must_be_exact() const; // true if arrays of such are never generic
1025 virtual const TypeAry* remove_speculative() const;
1026 virtual const Type* cleanup_speculative() const;
1027 #ifndef PRODUCT
1028 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
1029 #endif
1030 };
1031
1032 //------------------------------TypeVect---------------------------------------
1033 // Basic class of vector (mask) types.
1034 class TypeVect : public Type {
1035 const BasicType _elem_bt; // Vector's element type
1036 const uint _length; // Elements in vector (power of 2)
1037
1038 protected:
1039 TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1040 _elem_bt(elem_bt), _length(length) {}
1160
1161 const Type* xmeet(const Type* t) const;
1162
1163 bool singleton(void) const;
1164 bool has_non_array_interface() const;
1165 };
1166
1167 //------------------------------TypePtr----------------------------------------
1168 // Class of machine Pointer Types: raw data, instances or arrays.
1169 // If the _base enum is AnyPtr, then this refers to all of the above.
1170 // Otherwise the _base will indicate which subset of pointers is affected,
1171 // and the class will be inherited from.
1172 class TypePtr : public Type {
1173 friend class TypeNarrowPtr;
1174 friend class Type;
1175 protected:
1176 static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1177
1178 public:
1179 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
1180 protected:
1181 TypePtr(TYPES t, PTR ptr, int offset,
1182 relocInfo::relocType reloc,
1183 const TypePtr* speculative = nullptr,
1184 int inline_depth = InlineDepthBottom) :
1185 Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1186 _ptr(ptr), _reloc(reloc) {}
1187 static const PTR ptr_meet[lastPTR][lastPTR];
1188 static const PTR ptr_dual[lastPTR];
1189 static const char * const ptr_msg[lastPTR];
1190
1191 enum {
1192 InlineDepthBottom = INT_MAX,
1193 InlineDepthTop = -InlineDepthBottom
1194 };
1195
1196 // Extra type information profiling gave us. We propagate it the
1197 // same way the rest of the type info is propagated. If we want to
1198 // use it, then we have to emit a guard: this part of the type is
1199 // not something we know but something we speculate about the type.
1200 const TypePtr* _speculative;
1201 // For speculative types, we record at what inlining depth the
1202 // profiling point that provided the data is. We want to favor
1203 // profile data coming from outer scopes which are likely better for
1204 // the current compilation.
1205 int _inline_depth;
1206
1207 // utility methods to work on the speculative part of the type
1208 const TypePtr* dual_speculative() const;
1209 const TypePtr* xmeet_speculative(const TypePtr* other) const;
1210 bool eq_speculative(const TypePtr* other) const;
1219 #ifndef PRODUCT
1220 void dump_speculative(outputStream* st) const;
1221 void dump_inline_depth(outputStream* st) const;
1222 void dump_offset(outputStream* st) const;
1223 #endif
1224
1225 // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1226 // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1227 // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1228 // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1229 // encountered so the right logic specific to klasses or oops can be executed.,
1230 enum MeetResult {
1231 QUICK,
1232 UNLOADED,
1233 SUBTYPE,
1234 NOT_SUBTYPE,
1235 LCA
1236 };
1237 template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1238 const T* other_type, ciKlass*& res_klass, bool& res_xk);
1239
1240 template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1241 ciKlass*& res_klass, bool& res_xk);
1242
1243 template <class T1, class T2> static bool is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1244 template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1245 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1246 template <class T1, class T2> static bool is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1247 template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1248 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1249 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1250 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1251 public:
1252 const int _offset; // Offset into oop, with TOP & BOT
1253 const PTR _ptr; // Pointer equivalence class
1254 const relocInfo::relocType _reloc;
1255
1256 int offset() const { return _offset; }
1257 PTR ptr() const { return _ptr; }
1258 relocInfo::relocType reloc() const { return _reloc; }
1259
1260 static const TypePtr *make(TYPES t, PTR ptr, int offset,
1261 const TypePtr* speculative = nullptr,
1262 int inline_depth = InlineDepthBottom,
1263 relocInfo::relocType reloc = relocInfo::none);
1264
1265 // Return a 'ptr' version of this type
1266 virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1267
1268 virtual intptr_t get_con() const;
1269
1270 int xadd_offset( intptr_t offset ) const;
1271 virtual const TypePtr* add_offset(intptr_t offset) const;
1272 virtual const TypePtr* with_offset(intptr_t offset) const;
1273 virtual bool eq(const Type *t) const;
1274 virtual uint hash() const; // Type specific hashing
1275
1276 virtual bool singleton(void) const; // TRUE if type is a singleton
1277 virtual bool empty(void) const; // TRUE if type is vacuous
1278 virtual const Type *xmeet( const Type *t ) const;
1279 virtual const Type *xmeet_helper( const Type *t ) const;
1280 int meet_offset( int offset ) const;
1281 int dual_offset( ) const;
1282 virtual const Type *xdual() const; // Compute dual right now.
1283
1284 // meet, dual and join over pointer equivalence sets
1285 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1286 PTR dual_ptr() const { return ptr_dual[ptr()]; }
1287
1288 // This is textually confusing unless one recalls that
1289 // join(t) == dual()->meet(t->dual())->dual().
1290 PTR join_ptr( const PTR in_ptr ) const {
1291 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1292 }
1293
1294 // Speculative type helper methods.
1295 virtual const TypePtr* speculative() const { return _speculative; }
1296 int inline_depth() const { return _inline_depth; }
1297 virtual ciKlass* speculative_type() const;
1298 virtual ciKlass* speculative_type_not_null() const;
1299 virtual bool speculative_maybe_null() const;
1300 virtual bool speculative_always_null() const;
1301 virtual const TypePtr* remove_speculative() const;
1302 virtual const Type* cleanup_speculative() const;
1303 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1304 virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1305 virtual const TypePtr* with_inline_depth(int depth) const;
1306
1307 virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1308
1309 // Tests for relation to centerline of type lattice:
1310 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1311 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1312 // Convenience common pre-built types.
1313 static const TypePtr *NULL_PTR;
1314 static const TypePtr *NOTNULL;
1315 static const TypePtr *BOTTOM;
1316 #ifndef PRODUCT
1317 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1318 #endif
1319 };
1320
1321 //------------------------------TypeRawPtr-------------------------------------
1322 // Class of raw pointers, pointers to things other than Oops. Examples
1323 // include the stack pointer, top of heap, card-marking area, handles, etc.
1324 class TypeRawPtr : public TypePtr {
1325 protected:
1326 TypeRawPtr(PTR ptr, address bits, relocInfo::relocType reloc) : TypePtr(RawPtr, ptr, 0, reloc), _bits(bits){}
1327 public:
1328 virtual bool eq( const Type *t ) const;
1329 virtual uint hash() const; // Type specific hashing
1330
1331 const address _bits; // Constant value, if applicable
1332
1333 static const TypeRawPtr* make(PTR ptr);
1334 static const TypeRawPtr* make(address bits, relocInfo::relocType reloc = relocInfo::external_word_type);
1335
1336 // Return a 'ptr' version of this type
1337 virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1338
1339 virtual intptr_t get_con() const;
1340
1341 virtual const TypePtr* add_offset(intptr_t offset) const;
1342 virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1343
1344 virtual const Type *xmeet( const Type *t ) const;
1345 virtual const Type *xdual() const; // Compute dual right now.
1346 // Convenience common pre-built types.
1347 static const TypeRawPtr *BOTTOM;
1348 static const TypeRawPtr *NOTNULL;
1349 #ifndef PRODUCT
1350 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1351 #endif
1352 };
1353
1354 //------------------------------TypeOopPtr-------------------------------------
1355 // Some kind of oop (Java pointer), either instance or array.
1356 class TypeOopPtr : public TypePtr {
1357 friend class TypeAry;
1358 friend class TypePtr;
1359 friend class TypeInstPtr;
1360 friend class TypeAryPtr;
1361 protected:
1362 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1363 const TypePtr* speculative, int inline_depth);
1364 public:
1365 virtual bool eq( const Type *t ) const;
1366 virtual uint hash() const; // Type specific hashing
1367 virtual bool singleton(void) const; // TRUE if type is a singleton
1368 enum {
1369 InstanceTop = -1, // undefined instance
1370 InstanceBot = 0 // any possible instance
1371 };
1372 protected:
1373
1374 // Oop is null, unless this is a constant oop.
1375 ciObject* _const_oop; // Constant oop
1376 // If _klass is null, then so is _sig. This is an unloaded klass.
1377 ciKlass* _klass; // Klass object
1378
1379 const TypeInterfaces* _interfaces;
1380
1381 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1382 bool _klass_is_exact;
1383 bool _is_ptr_to_narrowoop;
1384 bool _is_ptr_to_narrowklass;
1385 bool _is_ptr_to_boxed_value;
1386
1387 // If not InstanceTop or InstanceBot, indicates that this is
1388 // a particular instance of this type which is distinct.
1389 // This is the node index of the allocation node creating this instance.
1390 int _instance_id;
1391
1392 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1393
1394 int dual_instance_id() const;
1395 int meet_instance_id(int uid) const;
1396
1397 const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1398
1399 // Do not allow interface-vs.-noninterface joins to collapse to top.
1400 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1401
1402 virtual ciKlass* exact_klass_helper() const { return nullptr; }
1403 virtual ciKlass* klass() const { return _klass; }
1404
1405 #ifndef PRODUCT
1406 void dump_instance_id(outputStream* st) const;
1407 #endif // PRODUCT
1408
1409 public:
1410
1411 bool is_java_subtype_of(const TypeOopPtr* other) const {
1412 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1413 }
1414
1415 bool is_same_java_type_as(const TypePtr* other) const {
1416 return is_same_java_type_as_helper(other->is_oopptr());
1417 }
1418
1419 virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1420 ShouldNotReachHere(); return false;
1421 }
1422
1423 bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1434 return make_from_klass_common(klass, true, false, interface_handling);
1435 }
1436 // Same as before, but will produce an exact type, even if
1437 // the klass is not final, as long as it has exactly one implementation.
1438 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1439 return make_from_klass_common(klass, true, true, interface_handling);
1440 }
1441 // Same as before, but does not respects UseUniqueSubclasses.
1442 // Use this only for creating array element types.
1443 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1444 return make_from_klass_common(klass, false, false, interface_handling);
1445 }
1446 // Creates a singleton type given an object.
1447 // If the object cannot be rendered as a constant,
1448 // may return a non-singleton type.
1449 // If require_constant, produce a null if a singleton is not possible.
1450 static const TypeOopPtr* make_from_constant(ciObject* o,
1451 bool require_constant = false);
1452
1453 // Make a generic (unclassed) pointer to an oop.
1454 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1455 const TypePtr* speculative = nullptr,
1456 int inline_depth = InlineDepthBottom);
1457
1458 ciObject* const_oop() const { return _const_oop; }
1459 // Exact klass, possibly an interface or an array of interface
1460 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1461 ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1462
1463 virtual bool is_loaded() const { return klass()->is_loaded(); }
1464 virtual bool klass_is_exact() const { return _klass_is_exact; }
1465
1466 // Returns true if this pointer points at memory which contains a
1467 // compressed oop references.
1468 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1469 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1470 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
1471 bool is_known_instance() const { return _instance_id > 0; }
1472 int instance_id() const { return _instance_id; }
1473 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
1474
1475 virtual intptr_t get_con() const;
1476
1477 virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1478
1479 virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1480
1481 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1482
1483 // corresponding pointer to klass, for a given instance
1484 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1485
1486 virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1487 virtual const TypePtr* add_offset(intptr_t offset) const;
1488
1489 // Speculative type helper methods.
1490 virtual const TypeOopPtr* remove_speculative() const;
1491 virtual const Type* cleanup_speculative() const;
1492 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1493 virtual const TypePtr* with_inline_depth(int depth) const;
1516 return _interfaces;
1517 };
1518
1519 const TypeOopPtr* is_reference_type(const Type* other) const {
1520 return other->isa_oopptr();
1521 }
1522
1523 const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1524 return other->isa_aryptr();
1525 }
1526
1527 const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1528 return other->isa_instptr();
1529 }
1530 };
1531
1532 //------------------------------TypeInstPtr------------------------------------
1533 // Class of Java object pointers, pointing either to non-array Java instances
1534 // or to a Klass* (including array klasses).
1535 class TypeInstPtr : public TypeOopPtr {
1536 TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1537 const TypePtr* speculative, int inline_depth);
1538 virtual bool eq( const Type *t ) const;
1539 virtual uint hash() const; // Type specific hashing
1540
1541 ciKlass* exact_klass_helper() const;
1542
1543 public:
1544
1545 // Instance klass, ignoring any interface
1546 ciInstanceKlass* instance_klass() const {
1547 assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1548 return klass()->as_instance_klass();
1549 }
1550
1551 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1552 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1553 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1554
1555 // Make a pointer to a constant oop.
1556 static const TypeInstPtr *make(ciObject* o) {
1557 ciKlass* k = o->klass();
1558 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1559 return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1560 }
1561 // Make a pointer to a constant oop with offset.
1562 static const TypeInstPtr *make(ciObject* o, int offset) {
1563 ciKlass* k = o->klass();
1564 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1565 return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1566 }
1567
1568 // Make a pointer to some value of type klass.
1569 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1570 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1571 return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1572 }
1573
1574 // Make a pointer to some non-polymorphic value of exactly type klass.
1575 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1576 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1577 return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1578 }
1579
1580 // Make a pointer to some value of type klass with offset.
1581 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1582 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1583 return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1584 }
1585
1586 static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
1587 int instance_id = InstanceBot,
1588 const TypePtr* speculative = nullptr,
1589 int inline_depth = InlineDepthBottom);
1590
1591 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {
1592 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1593 return make(ptr, k, interfaces, xk, o, offset, instance_id);
1594 }
1595
1596 // If this is a java.lang.Class constant, return the type for it or null.
1597 // Pass to Type::get_const_type to turn it to a type, which will usually
1598 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1599 ciType* java_mirror_type() const;
1600
1601 virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1602
1603 virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1604
1605 virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1606
1607 virtual const TypePtr* add_offset(intptr_t offset) const;
1608 virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1609
1610 // Speculative type helper methods.
1611 virtual const TypeInstPtr* remove_speculative() const;
1612 const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1613 virtual const TypePtr* with_inline_depth(int depth) const;
1614 virtual const TypePtr* with_instance_id(int instance_id) const;
1615
1616 // the core of the computation of the meet of 2 types
1617 virtual const Type *xmeet_helper(const Type *t) const;
1618 virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1619 virtual const Type *xdual() const; // Compute dual right now.
1620
1621 const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1622
1623 // Convenience common pre-built types.
1624 static const TypeInstPtr *NOTNULL;
1625 static const TypeInstPtr *BOTTOM;
1626 static const TypeInstPtr *MIRROR;
1627 static const TypeInstPtr *MARK;
1628 static const TypeInstPtr *KLASS;
1629 #ifndef PRODUCT
1630 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1631 #endif
1632
1633 private:
1634 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1635
1636 virtual bool is_meet_same_type_as(const TypePtr* other) const {
1637 return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1638 }
1639
1640 };
1641
1642 //------------------------------TypeAryPtr-------------------------------------
1643 // Class of Java array pointers
1644 class TypeAryPtr : public TypeOopPtr {
1645 friend class Type;
1646 friend class TypePtr;
1647 friend class TypeInterfaces;
1648
1649 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1650 int offset, int instance_id, bool is_autobox_cache,
1651 const TypePtr* speculative, int inline_depth)
1652 : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1653 _ary(ary),
1654 _is_autobox_cache(is_autobox_cache)
1655 {
1656 int dummy;
1657 bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1658
1659 if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1660 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1661 _offset != arrayOopDesc::klass_offset_in_bytes()) {
1662 _is_ptr_to_narrowoop = true;
1663 }
1664
1665 }
1666 virtual bool eq( const Type *t ) const;
1667 virtual uint hash() const; // Type specific hashing
1668 const TypeAry *_ary; // Array we point into
1669 const bool _is_autobox_cache;
1670
1671 ciKlass* compute_klass() const;
1672
1673 // A pointer to delay allocation to Type::Initialize_shared()
1674
1675 static const TypeInterfaces* _array_interfaces;
1676 ciKlass* exact_klass_helper() const;
1677 // Only guaranteed non null for array of basic types
1678 ciKlass* klass() const;
1679
1680 public:
1681
1682 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1683 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1684 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1685
1686 // returns base element type, an instance klass (and not interface) for object arrays
1687 const Type* base_element_type(int& dims) const;
1688
1689 // Accessors
1690 bool is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1691
1692 const TypeAry* ary() const { return _ary; }
1693 const Type* elem() const { return _ary->_elem; }
1694 const TypeInt* size() const { return _ary->_size; }
1695 bool is_stable() const { return _ary->_stable; }
1696
1697 bool is_autobox_cache() const { return _is_autobox_cache; }
1698
1699 static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1700 int instance_id = InstanceBot,
1701 const TypePtr* speculative = nullptr,
1702 int inline_depth = InlineDepthBottom);
1703 // Constant pointer to array
1704 static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1705 int instance_id = InstanceBot,
1706 const TypePtr* speculative = nullptr,
1707 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);
1708
1709 // Return a 'ptr' version of this type
1710 virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1711
1712 virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1713
1714 virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1715
1716 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1717 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1718
1719 virtual bool empty(void) const; // TRUE if type is vacuous
1720 virtual const TypePtr *add_offset( intptr_t offset ) const;
1721 virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1722 const TypeAryPtr* with_ary(const TypeAry* ary) const;
1723
1724 // Speculative type helper methods.
1725 virtual const TypeAryPtr* remove_speculative() const;
1726 virtual const TypePtr* with_inline_depth(int depth) const;
1727 virtual const TypePtr* with_instance_id(int instance_id) const;
1728
1729 // the core of the computation of the meet of 2 types
1730 virtual const Type *xmeet_helper(const Type *t) const;
1731 virtual const Type *xdual() const; // Compute dual right now.
1732
1733 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1734 int stable_dimension() const;
1735
1736 const TypeAryPtr* cast_to_autobox_cache() const;
1737
1738 static jint max_array_length(BasicType etype) ;
1739 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1740
1741 // Convenience common pre-built types.
1742 static const TypeAryPtr* BOTTOM;
1743 static const TypeAryPtr* RANGE;
1744 static const TypeAryPtr* OOPS;
1745 static const TypeAryPtr* NARROWOOPS;
1746 static const TypeAryPtr* BYTES;
1747 static const TypeAryPtr* SHORTS;
1748 static const TypeAryPtr* CHARS;
1749 static const TypeAryPtr* INTS;
1750 static const TypeAryPtr* LONGS;
1751 static const TypeAryPtr* FLOATS;
1752 static const TypeAryPtr* DOUBLES;
1753 // selects one of the above:
1754 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1755 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1756 return _array_body_type[elem];
1757 }
1758 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1759 // sharpen the type of an int which is used as an array size
1760 #ifndef PRODUCT
1761 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1762 #endif
1763 private:
1764 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1765 };
1766
1767 //------------------------------TypeMetadataPtr-------------------------------------
1768 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1769 class TypeMetadataPtr : public TypePtr {
1770 protected:
1771 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1772 // Do not allow interface-vs.-noninterface joins to collapse to top.
1773 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1774 public:
1775 virtual bool eq( const Type *t ) const;
1776 virtual uint hash() const; // Type specific hashing
1777 virtual bool singleton(void) const; // TRUE if type is a singleton
1778
1779 private:
1780 ciMetadata* _metadata;
1781
1782 public:
1783 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1784
1785 static const TypeMetadataPtr* make(ciMethod* m);
1786 static const TypeMetadataPtr* make(ciMethodData* m);
1787
1788 ciMetadata* metadata() const { return _metadata; }
1789
1790 virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1791
1792 virtual const TypePtr *add_offset( intptr_t offset ) const;
1793
1794 virtual const Type *xmeet( const Type *t ) const;
1795 virtual const Type *xdual() const; // Compute dual right now.
1796
1797 virtual intptr_t get_con() const;
1798
1799 // Convenience common pre-built types.
1800 static const TypeMetadataPtr *BOTTOM;
1801
1802 #ifndef PRODUCT
1803 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1804 #endif
1805 };
1806
1807 //------------------------------TypeKlassPtr-----------------------------------
1808 // Class of Java Klass pointers
1809 class TypeKlassPtr : public TypePtr {
1810 friend class TypeInstKlassPtr;
1811 friend class TypeAryKlassPtr;
1812 friend class TypePtr;
1813 protected:
1814 TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset);
1815
1816 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1817
1818 public:
1819 virtual bool eq( const Type *t ) const;
1820 virtual uint hash() const;
1821 virtual bool singleton(void) const; // TRUE if type is a singleton
1822
1823 protected:
1824
1825 ciKlass* _klass;
1826 const TypeInterfaces* _interfaces;
1827 const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1828 virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1829 virtual ciKlass* exact_klass_helper() const;
1830 virtual ciKlass* klass() const { return _klass; }
1831
1832 public:
1833
1834 bool is_java_subtype_of(const TypeKlassPtr* other) const {
1835 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1836 }
1837 bool is_same_java_type_as(const TypePtr* other) const {
1838 return is_same_java_type_as_helper(other->is_klassptr());
1839 }
1840
1841 bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1842 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1843 }
1844 virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1845 virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1846 virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1847
1848 // Exact klass, possibly an interface or an array of interface
1849 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1850 virtual bool klass_is_exact() const { return _ptr == Constant; }
1851
1852 static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1853 static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces);
1854
1855 virtual bool is_loaded() const { return _klass->is_loaded(); }
1856
1857 virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1858
1859 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1860
1861 // corresponding pointer to instance, for a given class
1862 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1863
1864 virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1865 virtual const Type *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1866 virtual const Type *xdual() const { ShouldNotReachHere(); return nullptr; }
1867
1868 virtual intptr_t get_con() const;
1869
1870 virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1871
1872 virtual const TypeKlassPtr* try_improve() const { return this; }
1873
1874 private:
1875 virtual bool is_meet_subtype_of(const TypePtr* other) const {
1876 return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1877 }
1878
1879 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1880 ShouldNotReachHere(); return false;
1881 }
1882
1883 virtual const TypeInterfaces* interfaces() const {
1884 return _interfaces;
1885 };
1886
1887 const TypeKlassPtr* is_reference_type(const Type* other) const {
1888 return other->isa_klassptr();
1889 }
1890
1891 const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1892 return other->isa_aryklassptr();
1893 }
1894
1895 const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1896 return other->isa_instklassptr();
1897 }
1898 };
1899
1900 // Instance klass pointer, mirrors TypeInstPtr
1901 class TypeInstKlassPtr : public TypeKlassPtr {
1902
1903 TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1904 : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {
1905 assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1906 }
1907
1908 virtual bool must_be_exact() const;
1909
1910 public:
1911 // Instance klass ignoring any interface
1912 ciInstanceKlass* instance_klass() const {
1913 assert(!klass()->is_interface(), "");
1914 return klass()->as_instance_klass();
1915 }
1916
1917 bool might_be_an_array() const;
1918
1919 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1920 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1921 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1922
1923 static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1924 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1925 return make(TypePtr::Constant, k, interfaces, 0);
1926 }
1927 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1928
1929 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {
1930 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1931 return make(ptr, k, interfaces, offset);
1932 }
1933
1934 virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1935
1936 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1937
1938 // corresponding pointer to instance, for a given class
1939 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1940 virtual uint hash() const;
1941 virtual bool eq(const Type *t) const;
1942
1943 virtual const TypePtr *add_offset( intptr_t offset ) const;
1944 virtual const Type *xmeet( const Type *t ) const;
1945 virtual const Type *xdual() const;
1946 virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1947
1948 virtual const TypeKlassPtr* try_improve() const;
1949
1950 // Convenience common pre-built types.
1951 static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1952 static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1953
1954 #ifndef PRODUCT
1955 virtual void dump2(Dict& d, uint depth, outputStream* st) const;
1956 #endif // PRODUCT
1957
1958 private:
1959 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1960 };
1961
1962 // Array klass pointer, mirrors TypeAryPtr
1963 class TypeAryKlassPtr : public TypeKlassPtr {
1964 friend class TypeInstKlassPtr;
1965 friend class Type;
1966 friend class TypePtr;
1967
1968 const Type *_elem;
1969
1970 static const TypeInterfaces* _array_interfaces;
1971 TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1972 : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1973 assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1974 }
1975
1976 virtual ciKlass* exact_klass_helper() const;
1977 // Only guaranteed non null for array of basic types
1978 virtual ciKlass* klass() const;
1979
1980 virtual bool must_be_exact() const;
1981
1982 public:
1983
1984 // returns base element type, an instance klass (and not interface) for object arrays
1985 const Type* base_element_type(int& dims) const;
1986
1987 static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1988
1989 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1990 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1991 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1992
1993 bool is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1994
1995 static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1996 static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1997
1998 const Type *elem() const { return _elem; }
1999
2000 virtual bool eq(const Type *t) const;
2001 virtual uint hash() const; // Type specific hashing
2002
2003 virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
2004
2005 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
2006
2007 // corresponding pointer to instance, for a given class
2008 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
2009
2010 virtual const TypePtr *add_offset( intptr_t offset ) const;
2011 virtual const Type *xmeet( const Type *t ) const;
2012 virtual const Type *xdual() const; // Compute dual right now.
2013
2014 virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
2015
2016 virtual bool empty(void) const {
2017 return TypeKlassPtr::empty() || _elem->empty();
2018 }
2019
2020 #ifndef PRODUCT
2021 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2022 #endif
2023 private:
2024 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2025 };
2026
2027 class TypeNarrowPtr : public Type {
2028 protected:
2029 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
2030
2031 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
2032 _ptrtype(ptrtype) {
2033 assert(ptrtype->offset() == 0 ||
2034 ptrtype->offset() == OffsetBot ||
2035 ptrtype->offset() == OffsetTop, "no real offsets");
2036 }
2037
2038 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2039 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
2135 }
2136
2137 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2138 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2139 }
2140
2141 public:
2142 static const TypeNarrowKlass *make( const TypePtr* type);
2143
2144 // static const TypeNarrowKlass *BOTTOM;
2145 static const TypeNarrowKlass *NULL_PTR;
2146
2147 #ifndef PRODUCT
2148 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2149 #endif
2150 };
2151
2152 //------------------------------TypeFunc---------------------------------------
2153 // Class of Array Types
2154 class TypeFunc : public Type {
2155 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
2156 virtual bool eq( const Type *t ) const;
2157 virtual uint hash() const; // Type specific hashing
2158 virtual bool singleton(void) const; // TRUE if type is a singleton
2159 virtual bool empty(void) const; // TRUE if type is vacuous
2160
2161 const TypeTuple* const _domain; // Domain of inputs
2162 const TypeTuple* const _range; // Range of results
2163
2164 public:
2165 // Constants are shared among ADLC and VM
2166 enum { Control = AdlcVMDeps::Control,
2167 I_O = AdlcVMDeps::I_O,
2168 Memory = AdlcVMDeps::Memory,
2169 FramePtr = AdlcVMDeps::FramePtr,
2170 ReturnAdr = AdlcVMDeps::ReturnAdr,
2171 Parms = AdlcVMDeps::Parms
2172 };
2173
2174
2175 // Accessors:
2176 const TypeTuple* domain() const { return _domain; }
2177 const TypeTuple* range() const { return _range; }
2178
2179 static const TypeFunc *make(ciMethod* method);
2180 static const TypeFunc *make(ciSignature signature, const Type* extra);
2181 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2182
2183 virtual const Type *xmeet( const Type *t ) const;
2184 virtual const Type *xdual() const; // Compute dual right now.
2185
2186 BasicType return_type() const;
2187
2188 #ifndef PRODUCT
2189 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2190 #endif
2191 // Convenience common pre-built types.
2192 };
2193
2194 //------------------------------accessors--------------------------------------
2195 inline bool Type::is_ptr_to_narrowoop() const {
2196 #ifdef _LP64
2197 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2198 #else
2199 return false;
2200 #endif
2201 }
2202
2203 inline bool Type::is_ptr_to_narrowklass() const {
2204 #ifdef _LP64
2205 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2206 #else
2207 return false;
2444 }
2445
2446 inline const TypeNarrowOop* Type::make_narrowoop() const {
2447 return (_base == NarrowOop) ? is_narrowoop() :
2448 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2449 }
2450
2451 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2452 return (_base == NarrowKlass) ? is_narrowklass() :
2453 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2454 }
2455
2456 inline bool Type::is_floatingpoint() const {
2457 if( (_base == HalfFloatCon) || (_base == HalfFloatBot) ||
2458 (_base == FloatCon) || (_base == FloatBot) ||
2459 (_base == DoubleCon) || (_base == DoubleBot) )
2460 return true;
2461 return false;
2462 }
2463
2464 template <>
2465 inline const TypeInt* Type::cast<TypeInt>() const {
2466 return is_int();
2467 }
2468
2469 template <>
2470 inline const TypeLong* Type::cast<TypeLong>() const {
2471 return is_long();
2472 }
2473
2474 template <>
2475 inline const TypeInt* Type::try_cast<TypeInt>() const {
2476 return isa_int();
2477 }
2478
2479 template <>
2480 inline const TypeLong* Type::try_cast<TypeLong>() const {
2481 return isa_long();
2482 }
2483
2489
2490 // For type queries and asserts
2491 #define is_intptr_t is_long
2492 #define isa_intptr_t isa_long
2493 #define find_intptr_t_type find_long_type
2494 #define find_intptr_t_con find_long_con
2495 #define TypeX TypeLong
2496 #define Type_X Type::Long
2497 #define TypeX_X TypeLong::LONG
2498 #define TypeX_ZERO TypeLong::ZERO
2499 // For 'ideal_reg' machine registers
2500 #define Op_RegX Op_RegL
2501 // For phase->intcon variants
2502 #define MakeConX longcon
2503 #define ConXNode ConLNode
2504 // For array index arithmetic
2505 #define MulXNode MulLNode
2506 #define AndXNode AndLNode
2507 #define OrXNode OrLNode
2508 #define CmpXNode CmpLNode
2509 #define SubXNode SubLNode
2510 #define LShiftXNode LShiftLNode
2511 // For object size computation:
2512 #define AddXNode AddLNode
2513 #define RShiftXNode RShiftLNode
2514 // For card marks and hashcodes
2515 #define URShiftXNode URShiftLNode
2516 // For pointer-sized accesses
2517 #define LoadXNode LoadLNode
2518 #define StoreXNode StoreLNode
2519 // Opcodes
2520 #define Op_LShiftX Op_LShiftL
2521 #define Op_AndX Op_AndL
2522 #define Op_AddX Op_AddL
2523 #define Op_SubX Op_SubL
2524 #define Op_XorX Op_XorL
2525 #define Op_URShiftX Op_URShiftL
2526 #define Op_LoadX Op_LoadL
2527 // conversions
2528 #define ConvI2X(x) ConvI2L(x)
2529 #define ConvL2X(x) (x)
2530 #define ConvX2I(x) ConvL2I(x)
2531 #define ConvX2L(x) (x)
2532 #define ConvX2UL(x) (x)
2533
2534 #else
2535
2536 // For type queries and asserts
2537 #define is_intptr_t is_int
2538 #define isa_intptr_t isa_int
2539 #define find_intptr_t_type find_int_type
2540 #define find_intptr_t_con find_int_con
2541 #define TypeX TypeInt
2542 #define Type_X Type::Int
2543 #define TypeX_X TypeInt::INT
2544 #define TypeX_ZERO TypeInt::ZERO
2545 // For 'ideal_reg' machine registers
2546 #define Op_RegX Op_RegI
2547 // For phase->intcon variants
2548 #define MakeConX intcon
2549 #define ConXNode ConINode
2550 // For array index arithmetic
2551 #define MulXNode MulINode
2552 #define AndXNode AndINode
2553 #define OrXNode OrINode
2554 #define CmpXNode CmpINode
2555 #define SubXNode SubINode
2556 #define LShiftXNode LShiftINode
2557 // For object size computation:
2558 #define AddXNode AddINode
2559 #define RShiftXNode RShiftINode
2560 // For card marks and hashcodes
2561 #define URShiftXNode URShiftINode
2562 // For pointer-sized accesses
2563 #define LoadXNode LoadINode
2564 #define StoreXNode StoreINode
2565 // Opcodes
2566 #define Op_LShiftX Op_LShiftI
2567 #define Op_AndX Op_AndI
2568 #define Op_AddX Op_AddI
2569 #define Op_SubX Op_SubI
2570 #define Op_XorX Op_XorI
2571 #define Op_URShiftX Op_URShiftI
2572 #define Op_LoadX Op_LoadI
2573 // conversions
2574 #define ConvI2X(x) (x)
2575 #define ConvL2X(x) ConvL2I(x)
2576 #define ConvX2I(x) (x)
2577 #define ConvX2L(x) ConvI2L(x)
2578 #define ConvX2UL(x) ConvI2UL(x)
2579
2580 #endif
2581
2582 #endif // SHARE_OPTO_TYPE_HPP
|
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 #ifndef SHARE_OPTO_TYPE_HPP
26 #define SHARE_OPTO_TYPE_HPP
27
28 #include "ci/ciInlineKlass.hpp"
29 #include "opto/adlcVMDeps.hpp"
30 #include "opto/compile.hpp"
31 #include "opto/rangeinference.hpp"
32
33 // Portions of code courtesy of Clifford Click
34
35 // Optimization - Graph Style
36
37
38 // This class defines a Type lattice. The lattice is used in the constant
39 // propagation algorithms, and for some type-checking of the iloc code.
40 // Basic types include RSD's (lower bound, upper bound, stride for integers),
41 // float & double precision constants, sets of data-labels and code-labels.
42 // The complete lattice is described below. Subtypes have no relationship to
43 // up or down in the lattice; that is entirely determined by the behavior of
44 // the MEET/JOIN functions.
45
46 class Dict;
47 class Type;
48 class TypeD;
49 class TypeF;
50 class TypeH;
51 class TypeInteger;
127 Memory, // Abstract store
128 HalfFloatTop, // No float value
129 HalfFloatCon, // Floating point constant
130 HalfFloatBot, // Any float value
131 FloatTop, // No float value
132 FloatCon, // Floating point constant
133 FloatBot, // Any float value
134 DoubleTop, // No double value
135 DoubleCon, // Double precision constant
136 DoubleBot, // Any double value
137 Bottom, // Bottom of lattice
138 lastype // Bogus ending type (not in lattice)
139 };
140
141 // Signal values for offsets from a base pointer
142 enum OFFSET_SIGNALS {
143 OffsetTop = -2000000000, // undefined offset
144 OffsetBot = -2000000001 // any possible offset
145 };
146
147 class Offset {
148 private:
149 int _offset;
150
151 public:
152 explicit Offset(int offset) : _offset(offset) {}
153
154 const Offset meet(const Offset other) const;
155 const Offset dual() const;
156 const Offset add(intptr_t offset) const;
157 bool operator==(const Offset& other) const {
158 return _offset == other._offset;
159 }
160 bool operator!=(const Offset& other) const {
161 return _offset != other._offset;
162 }
163 int get() const { return _offset; }
164
165 void dump2(outputStream *st) const;
166
167 static const Offset top;
168 static const Offset bottom;
169 };
170
171 // Min and max WIDEN values.
172 enum WIDEN {
173 WidenMin = 0,
174 WidenMax = 3
175 };
176
177 private:
178 typedef struct {
179 TYPES dual_type;
180 BasicType basic_type;
181 const char* msg;
182 bool isa_oop;
183 uint ideal_reg;
184 } TypeInfo;
185
186 // Dictionary of types shared among compilations.
187 static Dict* _shared_type_dict;
188 static const TypeInfo _type_info[];
189
190 static int uhash( const Type *const t );
351 const TypeInstPtr *isa_instptr() const; // Returns null if not InstPtr
352 const TypeInstPtr *is_instptr() const; // Instance
353 const TypeAryPtr *isa_aryptr() const; // Returns null if not AryPtr
354 const TypeAryPtr *is_aryptr() const; // Array oop
355
356 template <typename TypeClass>
357 const TypeClass* cast() const;
358
359 const TypeMetadataPtr *isa_metadataptr() const; // Returns null if not oop ptr type
360 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer
361 const TypeKlassPtr *isa_klassptr() const; // Returns null if not KlassPtr
362 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
363 const TypeInstKlassPtr *isa_instklassptr() const; // Returns null if not IntKlassPtr
364 const TypeInstKlassPtr *is_instklassptr() const; // assert if not IntKlassPtr
365 const TypeAryKlassPtr *isa_aryklassptr() const; // Returns null if not AryKlassPtr
366 const TypeAryKlassPtr *is_aryklassptr() const; // assert if not AryKlassPtr
367
368 virtual bool is_finite() const; // Has a finite value
369 virtual bool is_nan() const; // Is not a number (NaN)
370
371 bool is_inlinetypeptr() const;
372 virtual ciInlineKlass* inline_klass() const;
373
374 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
375 const TypePtr* make_ptr() const;
376
377 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
378 // Asserts if the underlying type is not an oopptr or narrowoop.
379 const TypeOopPtr* make_oopptr() const;
380
381 // Returns this compressed pointer or the equivalent compressed version
382 // of this pointer type.
383 const TypeNarrowOop* make_narrowoop() const;
384
385 // Returns this compressed klass pointer or the equivalent
386 // compressed version of this pointer type.
387 const TypeNarrowKlass* make_narrowklass() const;
388
389 // Special test for register pressure heuristic
390 bool is_floatingpoint() const; // True if Float or Double base type
391
392 // Do you have memory, directly or through a tuple?
393 bool has_memory( ) const;
490 static const Type* get_typeflow_type(ciType* type);
491
492 static const Type* make_from_constant(ciConstant constant,
493 bool require_constant = false,
494 int stable_dimension = 0,
495 bool is_narrow = false,
496 bool is_autobox_cache = false);
497
498 static const Type* make_constant_from_field(ciInstance* holder,
499 int off,
500 bool is_unsigned_load,
501 BasicType loadbt);
502
503 static const Type* make_constant_from_field(ciField* field,
504 ciInstance* holder,
505 BasicType loadbt,
506 bool is_unsigned_load);
507
508 static const Type* make_constant_from_array_element(ciArray* array,
509 int off,
510 int field_offset,
511 int stable_dimension,
512 BasicType loadbt,
513 bool is_unsigned_load);
514
515 // Speculative type helper methods. See TypePtr.
516 virtual const TypePtr* speculative() const { return nullptr; }
517 virtual ciKlass* speculative_type() const { return nullptr; }
518 virtual ciKlass* speculative_type_not_null() const { return nullptr; }
519 virtual bool speculative_maybe_null() const { return true; }
520 virtual bool speculative_always_null() const { return true; }
521 virtual const Type* remove_speculative() const { return this; }
522 virtual const Type* cleanup_speculative() const { return this; }
523 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != nullptr; }
524 virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
525 const Type* maybe_remove_speculative(bool include_speculative) const;
526
527 virtual bool maybe_null() const { return true; }
528 virtual bool is_known_instance() const { return false; }
529
530 private:
983 const Type ** const _fields; // Array of field types
984
985 public:
986 virtual bool eq( const Type *t ) const;
987 virtual uint hash() const; // Type specific hashing
988 virtual bool singleton(void) const; // TRUE if type is a singleton
989 virtual bool empty(void) const; // TRUE if type is vacuous
990
991 // Accessors:
992 uint cnt() const { return _cnt; }
993 const Type* field_at(uint i) const {
994 assert(i < _cnt, "oob");
995 return _fields[i];
996 }
997 void set_field_at(uint i, const Type* t) {
998 assert(i < _cnt, "oob");
999 _fields[i] = t;
1000 }
1001
1002 static const TypeTuple *make( uint cnt, const Type **fields );
1003 static const TypeTuple *make_range(ciSignature* sig, InterfaceHandling interface_handling = ignore_interfaces, bool ret_vt_fields = false, bool is_call = false);
1004 static const TypeTuple *make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args = false);
1005
1006 // Subroutine call type with space allocated for argument types
1007 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1008 static const Type **fields( uint arg_cnt );
1009
1010 virtual const Type *xmeet( const Type *t ) const;
1011 virtual const Type *xdual() const; // Compute dual right now.
1012 // Convenience common pre-built types.
1013 static const TypeTuple *IFBOTH;
1014 static const TypeTuple *IFFALSE;
1015 static const TypeTuple *IFTRUE;
1016 static const TypeTuple *IFNEITHER;
1017 static const TypeTuple *LOOPBODY;
1018 static const TypeTuple *MEMBAR;
1019 static const TypeTuple *STORECONDITIONAL;
1020 static const TypeTuple *START_I2C;
1021 static const TypeTuple *INT_PAIR;
1022 static const TypeTuple *LONG_PAIR;
1023 static const TypeTuple *INT_CC_PAIR;
1024 static const TypeTuple *LONG_CC_PAIR;
1025 #ifndef PRODUCT
1026 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
1027 #endif
1028 };
1029
1030 //------------------------------TypeAry----------------------------------------
1031 // Class of Array Types
1032 class TypeAry : public Type {
1033 TypeAry(const Type* elem, const TypeInt* size, bool stable, bool flat, bool not_flat, bool not_null_free, bool atomic) : Type(Array),
1034 _elem(elem), _size(size), _stable(stable), _flat(flat), _not_flat(not_flat), _not_null_free(not_null_free), _atomic(atomic) {}
1035 public:
1036 virtual bool eq( const Type *t ) const;
1037 virtual uint hash() const; // Type specific hashing
1038 virtual bool singleton(void) const; // TRUE if type is a singleton
1039 virtual bool empty(void) const; // TRUE if type is vacuous
1040
1041 private:
1042 const Type *_elem; // Element type of array
1043 const TypeInt *_size; // Elements in array
1044 const bool _stable; // Are elements @Stable?
1045
1046 // Inline type array properties
1047 const bool _flat; // Array is flat
1048 const bool _not_flat; // Array is never flat
1049 const bool _not_null_free; // Array is never null-free
1050 const bool _atomic; // Array is atomic
1051
1052 friend class TypeAryPtr;
1053
1054 public:
1055 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable,
1056 bool flat, bool not_flat, bool not_null_free, bool atomic);
1057
1058 virtual const Type *xmeet( const Type *t ) const;
1059 virtual const Type *xdual() const; // Compute dual right now.
1060 bool ary_must_be_exact() const; // true if arrays of such are never generic
1061 virtual const TypeAry* remove_speculative() const;
1062 virtual const Type* cleanup_speculative() const;
1063 #ifndef PRODUCT
1064 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
1065 #endif
1066 };
1067
1068 //------------------------------TypeVect---------------------------------------
1069 // Basic class of vector (mask) types.
1070 class TypeVect : public Type {
1071 const BasicType _elem_bt; // Vector's element type
1072 const uint _length; // Elements in vector (power of 2)
1073
1074 protected:
1075 TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1076 _elem_bt(elem_bt), _length(length) {}
1196
1197 const Type* xmeet(const Type* t) const;
1198
1199 bool singleton(void) const;
1200 bool has_non_array_interface() const;
1201 };
1202
1203 //------------------------------TypePtr----------------------------------------
1204 // Class of machine Pointer Types: raw data, instances or arrays.
1205 // If the _base enum is AnyPtr, then this refers to all of the above.
1206 // Otherwise the _base will indicate which subset of pointers is affected,
1207 // and the class will be inherited from.
1208 class TypePtr : public Type {
1209 friend class TypeNarrowPtr;
1210 friend class Type;
1211 protected:
1212 static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1213
1214 public:
1215 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
1216
1217 // Only applies to TypeInstPtr and TypeInstKlassPtr. Since the common super class is TypePtr, it is defined here.
1218 //
1219 // FlatInArray defines the following Boolean Lattice structure
1220 //
1221 // TopFlat
1222 // / \
1223 // Flat NotFlat
1224 // \ /
1225 // MaybeFlat
1226 //
1227 // with meet (see TypePtr::meet_flat_in_array()) and join (implemented over dual, see TypePtr::flat_in_array_dual)
1228 enum FlatInArray {
1229 TopFlat, // Dedicated top element and dual of MaybeFlat. Result when joining Flat and NotFlat.
1230 Flat, // An instance is always flat in an array.
1231 NotFlat, // An instance is never flat in an array.
1232 MaybeFlat, // We don't know whether an instance is flat in an array.
1233 Uninitialized // Used when the flat in array property was not computed, yet - should never actually end up in a type.
1234 };
1235 protected:
1236 TypePtr(TYPES t, PTR ptr, Offset offset,
1237 relocInfo::relocType reloc,
1238 const TypePtr* speculative = nullptr,
1239 int inline_depth = InlineDepthBottom) :
1240 Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1241 _ptr(ptr), _reloc(reloc) {}
1242 static const PTR ptr_meet[lastPTR][lastPTR];
1243 static const PTR ptr_dual[lastPTR];
1244 static const char * const ptr_msg[lastPTR];
1245
1246 static const FlatInArray flat_in_array_dual[Uninitialized];
1247 static const char* const flat_in_array_msg[Uninitialized];
1248
1249 enum {
1250 InlineDepthBottom = INT_MAX,
1251 InlineDepthTop = -InlineDepthBottom
1252 };
1253
1254 // Extra type information profiling gave us. We propagate it the
1255 // same way the rest of the type info is propagated. If we want to
1256 // use it, then we have to emit a guard: this part of the type is
1257 // not something we know but something we speculate about the type.
1258 const TypePtr* _speculative;
1259 // For speculative types, we record at what inlining depth the
1260 // profiling point that provided the data is. We want to favor
1261 // profile data coming from outer scopes which are likely better for
1262 // the current compilation.
1263 int _inline_depth;
1264
1265 // utility methods to work on the speculative part of the type
1266 const TypePtr* dual_speculative() const;
1267 const TypePtr* xmeet_speculative(const TypePtr* other) const;
1268 bool eq_speculative(const TypePtr* other) const;
1277 #ifndef PRODUCT
1278 void dump_speculative(outputStream* st) const;
1279 void dump_inline_depth(outputStream* st) const;
1280 void dump_offset(outputStream* st) const;
1281 #endif
1282
1283 // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1284 // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1285 // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1286 // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1287 // encountered so the right logic specific to klasses or oops can be executed.,
1288 enum MeetResult {
1289 QUICK,
1290 UNLOADED,
1291 SUBTYPE,
1292 NOT_SUBTYPE,
1293 LCA
1294 };
1295 template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1296 const T* other_type, ciKlass*& res_klass, bool& res_xk);
1297 protected:
1298 static FlatInArray meet_flat_in_array(FlatInArray left, FlatInArray other);
1299
1300 template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1301 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool &res_not_flat, bool &res_not_null_free, bool &res_atomic);
1302
1303 template <class T1, class T2> static bool is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1304 template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1305 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1306 template <class T1, class T2> static bool is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1307 template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1308 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1309 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1310 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1311 public:
1312 const Offset _offset; // Offset into oop, with TOP & BOT
1313 const PTR _ptr; // Pointer equivalence class
1314 const relocInfo::relocType _reloc;
1315
1316 int offset() const { return _offset.get(); }
1317 PTR ptr() const { return _ptr; }
1318 relocInfo::relocType reloc() const { return _reloc; }
1319
1320 static const TypePtr* make(TYPES t, PTR ptr, Offset offset,
1321 const TypePtr* speculative = nullptr,
1322 int inline_depth = InlineDepthBottom,
1323 relocInfo::relocType reloc = relocInfo::none);
1324
1325 // Return a 'ptr' version of this type
1326 virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1327
1328 virtual intptr_t get_con() const;
1329
1330 Type::Offset xadd_offset(intptr_t offset) const;
1331 virtual const TypePtr* add_offset(intptr_t offset) const;
1332 virtual const TypePtr* with_offset(intptr_t offset) const;
1333 virtual int flat_offset() const { return offset(); }
1334 virtual bool eq(const Type *t) const;
1335 virtual uint hash() const; // Type specific hashing
1336
1337 virtual bool singleton(void) const; // TRUE if type is a singleton
1338 virtual bool empty(void) const; // TRUE if type is vacuous
1339 virtual const Type *xmeet( const Type *t ) const;
1340 virtual const Type *xmeet_helper( const Type *t ) const;
1341 Offset meet_offset(int offset) const;
1342 Offset dual_offset() const;
1343 virtual const Type *xdual() const; // Compute dual right now.
1344
1345 // meet, dual and join over pointer equivalence sets
1346 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1347 PTR dual_ptr() const { return ptr_dual[ptr()]; }
1348
1349 // This is textually confusing unless one recalls that
1350 // join(t) == dual()->meet(t->dual())->dual().
1351 PTR join_ptr( const PTR in_ptr ) const {
1352 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1353 }
1354
1355 // Speculative type helper methods.
1356 virtual const TypePtr* speculative() const { return _speculative; }
1357 int inline_depth() const { return _inline_depth; }
1358 virtual ciKlass* speculative_type() const;
1359 virtual ciKlass* speculative_type_not_null() const;
1360 virtual bool speculative_maybe_null() const;
1361 virtual bool speculative_always_null() const;
1362 virtual const TypePtr* remove_speculative() const;
1363 virtual const Type* cleanup_speculative() const;
1364 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1365 virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1366 virtual const TypePtr* with_inline_depth(int depth) const;
1367
1368 virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1369
1370 NOT_PRODUCT(static void dump_flat_in_array(FlatInArray flat_in_array, outputStream* st);)
1371
1372 static FlatInArray compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact);
1373
1374 static FlatInArray compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
1375 FlatInArray old_flat_in_array);
1376
1377 virtual bool can_be_inline_type() const { return false; }
1378 virtual bool is_flat_in_array() const { return flat_in_array() == Flat; }
1379 virtual bool is_not_flat_in_array() const { return flat_in_array() == NotFlat; }
1380 virtual FlatInArray flat_in_array() const { return NotFlat; }
1381 virtual bool is_flat() const { return false; }
1382 virtual bool is_not_flat() const { return false; }
1383 virtual bool is_null_free() const { return false; }
1384 virtual bool is_not_null_free() const { return false; }
1385 virtual bool is_atomic() const { return false; }
1386
1387 // Tests for relation to centerline of type lattice:
1388 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1389 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1390 // Convenience common pre-built types.
1391 static const TypePtr *NULL_PTR;
1392 static const TypePtr *NOTNULL;
1393 static const TypePtr *BOTTOM;
1394 #ifndef PRODUCT
1395 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1396 #endif
1397 };
1398
1399 //------------------------------TypeRawPtr-------------------------------------
1400 // Class of raw pointers, pointers to things other than Oops. Examples
1401 // include the stack pointer, top of heap, card-marking area, handles, etc.
1402 class TypeRawPtr : public TypePtr {
1403 protected:
1404 TypeRawPtr(PTR ptr, address bits, relocInfo::relocType reloc) : TypePtr(RawPtr, ptr, Offset(0), reloc), _bits(bits){}
1405 public:
1406 virtual bool eq( const Type *t ) const;
1407 virtual uint hash() const; // Type specific hashing
1408
1409 const address _bits; // Constant value, if applicable
1410
1411 static const TypeRawPtr* make(PTR ptr);
1412 static const TypeRawPtr* make(address bits, relocInfo::relocType reloc = relocInfo::external_word_type);
1413
1414 // Return a 'ptr' version of this type
1415 virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1416
1417 virtual intptr_t get_con() const;
1418
1419 virtual const TypePtr* add_offset(intptr_t offset) const;
1420 virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1421
1422 virtual const Type *xmeet( const Type *t ) const;
1423 virtual const Type *xdual() const; // Compute dual right now.
1424 // Convenience common pre-built types.
1425 static const TypeRawPtr *BOTTOM;
1426 static const TypeRawPtr *NOTNULL;
1427 #ifndef PRODUCT
1428 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1429 #endif
1430 };
1431
1432 //------------------------------TypeOopPtr-------------------------------------
1433 // Some kind of oop (Java pointer), either instance or array.
1434 class TypeOopPtr : public TypePtr {
1435 friend class TypeAry;
1436 friend class TypePtr;
1437 friend class TypeInstPtr;
1438 friend class TypeAryPtr;
1439 protected:
1440 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset, int instance_id,
1441 const TypePtr* speculative, int inline_depth);
1442 public:
1443 virtual bool eq( const Type *t ) const;
1444 virtual uint hash() const; // Type specific hashing
1445 virtual bool singleton(void) const; // TRUE if type is a singleton
1446 enum {
1447 InstanceTop = -1, // undefined instance
1448 InstanceBot = 0 // any possible instance
1449 };
1450 protected:
1451
1452 // Oop is null, unless this is a constant oop.
1453 ciObject* _const_oop; // Constant oop
1454 // If _klass is null, then so is _sig. This is an unloaded klass.
1455 ciKlass* _klass; // Klass object
1456
1457 const TypeInterfaces* _interfaces;
1458
1459 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1460 bool _klass_is_exact;
1461 bool _is_ptr_to_narrowoop;
1462 bool _is_ptr_to_narrowklass;
1463 bool _is_ptr_to_boxed_value;
1464 bool _is_ptr_to_strict_final_field;
1465
1466 // If not InstanceTop or InstanceBot, indicates that this is
1467 // a particular instance of this type which is distinct.
1468 // This is the node index of the allocation node creating this instance.
1469 int _instance_id;
1470
1471 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1472
1473 int dual_instance_id() const;
1474 int meet_instance_id(int uid) const;
1475
1476 const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1477
1478 // Do not allow interface-vs.-noninterface joins to collapse to top.
1479 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1480
1481 virtual ciKlass* exact_klass_helper() const { return nullptr; }
1482 virtual ciKlass* klass() const { return _klass; }
1483
1484 #ifndef PRODUCT
1485 void dump_instance_id(outputStream* st) const;
1486 #endif // PRODUCT
1487
1488 public:
1489
1490 bool is_java_subtype_of(const TypeOopPtr* other) const {
1491 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1492 }
1493
1494 bool is_same_java_type_as(const TypePtr* other) const {
1495 return is_same_java_type_as_helper(other->is_oopptr());
1496 }
1497
1498 virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1499 ShouldNotReachHere(); return false;
1500 }
1501
1502 bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1513 return make_from_klass_common(klass, true, false, interface_handling);
1514 }
1515 // Same as before, but will produce an exact type, even if
1516 // the klass is not final, as long as it has exactly one implementation.
1517 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1518 return make_from_klass_common(klass, true, true, interface_handling);
1519 }
1520 // Same as before, but does not respects UseUniqueSubclasses.
1521 // Use this only for creating array element types.
1522 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1523 return make_from_klass_common(klass, false, false, interface_handling);
1524 }
1525 // Creates a singleton type given an object.
1526 // If the object cannot be rendered as a constant,
1527 // may return a non-singleton type.
1528 // If require_constant, produce a null if a singleton is not possible.
1529 static const TypeOopPtr* make_from_constant(ciObject* o,
1530 bool require_constant = false);
1531
1532 // Make a generic (unclassed) pointer to an oop.
1533 static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id,
1534 const TypePtr* speculative = nullptr,
1535 int inline_depth = InlineDepthBottom);
1536
1537 ciObject* const_oop() const { return _const_oop; }
1538 // Exact klass, possibly an interface or an array of interface
1539 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1540 ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1541
1542 virtual bool is_loaded() const { return klass()->is_loaded(); }
1543 virtual bool klass_is_exact() const { return _klass_is_exact; }
1544
1545 // Returns true if this pointer points at memory which contains a
1546 // compressed oop references.
1547 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1548 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1549 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
1550 bool is_ptr_to_strict_final_field() const { return _is_ptr_to_strict_final_field; }
1551 bool is_known_instance() const { return _instance_id > 0; }
1552 int instance_id() const { return _instance_id; }
1553 bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; }
1554 bool same_instance_as(const TypeOopPtr* t) const {
1555 assert(is_known_instance() || t->is_known_instance(), "known instance expected");
1556 // Once EA has run, some node's TypeOopPtrs are assigned a "known instance" instance_id. Others are left with
1557 // an unknown instance instance_id: InstanceBot. The nodes with InstanceBot are from any instance other than the
1558 // ones that are known, that is, InstanceBot and "known instance" instance_ids don't alias. As a consequence,
1559 // comparing an InstanceBot type with a known instance type is valid and this method correctly returns false in that
1560 // case.
1561 return instance_id() == t->instance_id();
1562 }
1563
1564 virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(_klass_is_exact)); }
1565 virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
1566
1567 virtual intptr_t get_con() const;
1568
1569 virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1570
1571 virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1572
1573 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1574
1575 // corresponding pointer to klass, for a given instance
1576 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1577
1578 virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1579 virtual const TypePtr* add_offset(intptr_t offset) const;
1580
1581 // Speculative type helper methods.
1582 virtual const TypeOopPtr* remove_speculative() const;
1583 virtual const Type* cleanup_speculative() const;
1584 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1585 virtual const TypePtr* with_inline_depth(int depth) const;
1608 return _interfaces;
1609 };
1610
1611 const TypeOopPtr* is_reference_type(const Type* other) const {
1612 return other->isa_oopptr();
1613 }
1614
1615 const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1616 return other->isa_aryptr();
1617 }
1618
1619 const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1620 return other->isa_instptr();
1621 }
1622 };
1623
1624 //------------------------------TypeInstPtr------------------------------------
1625 // Class of Java object pointers, pointing either to non-array Java instances
1626 // or to a Klass* (including array klasses).
1627 class TypeInstPtr : public TypeOopPtr {
1628 // Can this instance be in a flat array?
1629 FlatInArray _flat_in_array;
1630
1631 TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1632 FlatInArray flat_in_array, int instance_id, const TypePtr* speculative,
1633 int inline_depth);
1634 virtual bool eq( const Type *t ) const;
1635 virtual uint hash() const; // Type specific hashing
1636 ciKlass* exact_klass_helper() const;
1637
1638 public:
1639
1640 // Instance klass, ignoring any interface
1641 ciInstanceKlass* instance_klass() const {
1642 assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1643 return klass()->as_instance_klass();
1644 }
1645
1646 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1647 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1648 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1649
1650 // Make a pointer to a constant oop.
1651 static const TypeInstPtr *make(ciObject* o) {
1652 ciKlass* k = o->klass();
1653 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1654 return make(TypePtr::Constant, k, interfaces, true, o, Offset(0));
1655 }
1656 // Make a pointer to a constant oop with offset.
1657 static const TypeInstPtr *make(ciObject* o, Offset offset) {
1658 ciKlass* k = o->klass();
1659 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1660 return make(TypePtr::Constant, k, interfaces, true, o, offset);
1661 }
1662
1663 // Make a pointer to some value of type klass.
1664 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1665 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1666 return make(ptr, klass, interfaces, false, nullptr, Offset(0));
1667 }
1668
1669 // Make a pointer to some non-polymorphic value of exactly type klass.
1670 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1671 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1672 return make(ptr, klass, interfaces, true, nullptr, Offset(0));
1673 }
1674
1675 // Make a pointer to some value of type klass with offset.
1676 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, Offset offset) {
1677 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1678 return make(ptr, klass, interfaces, false, nullptr, offset);
1679 }
1680
1681 // Make a pointer to an oop.
1682 static const TypeInstPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1683 FlatInArray flat_in_array = Uninitialized,
1684 int instance_id = InstanceBot,
1685 const TypePtr* speculative = nullptr,
1686 int inline_depth = InlineDepthBottom);
1687
1688 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, int instance_id = InstanceBot,
1689 FlatInArray flat_in_array = Uninitialized) {
1690 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1691 return make(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id);
1692 }
1693
1694 // If this is a java.lang.Class constant, return the type for it or null.
1695 // Pass to Type::get_const_type to turn it to a type, which will usually
1696 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1697 ciType* java_mirror_type() const;
1698
1699 virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1700
1701 virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1702
1703 virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1704
1705 virtual bool empty() const;
1706 virtual const TypePtr* add_offset(intptr_t offset) const;
1707 virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1708
1709 // Speculative type helper methods.
1710 virtual const TypeInstPtr* remove_speculative() const;
1711 const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1712 virtual const TypePtr* with_inline_depth(int depth) const;
1713 virtual const TypePtr* with_instance_id(int instance_id) const;
1714
1715 virtual const TypeInstPtr* cast_to_flat_in_array() const;
1716 virtual const TypeInstPtr* cast_to_maybe_flat_in_array() const;
1717 virtual FlatInArray flat_in_array() const { return _flat_in_array; }
1718
1719 FlatInArray dual_flat_in_array() const {
1720 return flat_in_array_dual[_flat_in_array];
1721 }
1722
1723 // the core of the computation of the meet of 2 types
1724 virtual const Type *xmeet_helper(const Type *t) const;
1725 virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1726 virtual const Type *xdual() const; // Compute dual right now.
1727
1728 const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1729
1730 virtual bool can_be_inline_array() const;
1731
1732 // Convenience common pre-built types.
1733 static const TypeInstPtr *NOTNULL;
1734 static const TypeInstPtr *BOTTOM;
1735 static const TypeInstPtr *MIRROR;
1736 static const TypeInstPtr *MARK;
1737 static const TypeInstPtr *KLASS;
1738 #ifndef PRODUCT
1739 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1740 #endif
1741
1742 private:
1743 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1744
1745 virtual bool is_meet_same_type_as(const TypePtr* other) const {
1746 return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1747 }
1748
1749 };
1750
1751 //------------------------------TypeAryPtr-------------------------------------
1752 // Class of Java array pointers
1753 class TypeAryPtr : public TypeOopPtr {
1754 friend class Type;
1755 friend class TypePtr;
1756 friend class TypeInstPtr;
1757 friend class TypeInterfaces;
1758
1759 TypeAryPtr(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1760 Offset offset, Offset field_offset, int instance_id, bool is_autobox_cache,
1761 const TypePtr* speculative, int inline_depth)
1762 : TypeOopPtr(AryPtr, ptr, k, _array_interfaces, xk, o, offset, field_offset, instance_id, speculative, inline_depth),
1763 _ary(ary),
1764 _is_autobox_cache(is_autobox_cache),
1765 _field_offset(field_offset)
1766 {
1767 int dummy;
1768 bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1769
1770 if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1771 _offset.get() != 0 && _offset.get() != arrayOopDesc::length_offset_in_bytes() &&
1772 _offset.get() != arrayOopDesc::klass_offset_in_bytes()) {
1773 _is_ptr_to_narrowoop = true;
1774 }
1775
1776 }
1777 virtual bool eq( const Type *t ) const;
1778 virtual uint hash() const; // Type specific hashing
1779 const TypeAry *_ary; // Array we point into
1780 const bool _is_autobox_cache;
1781 // For flat inline type arrays, each field of the inline type in
1782 // the array has its own memory slice so we need to keep track of
1783 // which field is accessed
1784 const Offset _field_offset;
1785 Offset meet_field_offset(const Type::Offset offset) const;
1786 Offset dual_field_offset() const;
1787
1788 ciKlass* compute_klass() const;
1789
1790 // A pointer to delay allocation to Type::Initialize_shared()
1791
1792 static const TypeInterfaces* _array_interfaces;
1793 ciKlass* exact_klass_helper() const;
1794 // Only guaranteed non null for array of basic types
1795 ciKlass* klass() const;
1796
1797 public:
1798
1799 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1800 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1801 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1802
1803 // returns base element type, an instance klass (and not interface) for object arrays
1804 const Type* base_element_type(int& dims) const;
1805
1806 // Accessors
1807 bool is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1808
1809 const TypeAry* ary() const { return _ary; }
1810 const Type* elem() const { return _ary->_elem; }
1811 const TypeInt* size() const { return _ary->_size; }
1812 bool is_stable() const { return _ary->_stable; }
1813
1814 // Inline type array properties
1815 bool is_flat() const { return _ary->_flat; }
1816 bool is_not_flat() const { return _ary->_not_flat; }
1817 bool is_null_free() const { return _ary->_elem->make_ptr() != nullptr && (_ary->_elem->make_ptr()->ptr() == NotNull || _ary->_elem->make_ptr()->ptr() == AnyNull); }
1818 bool is_not_null_free() const { return _ary->_not_null_free; }
1819 bool is_atomic() const { return _ary->_atomic; }
1820
1821 bool is_autobox_cache() const { return _is_autobox_cache; }
1822
1823 static const TypeAryPtr* make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1824 Offset field_offset = Offset::bottom,
1825 int instance_id = InstanceBot,
1826 const TypePtr* speculative = nullptr,
1827 int inline_depth = InlineDepthBottom);
1828 // Constant pointer to array
1829 static const TypeAryPtr* make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1830 Offset field_offset = Offset::bottom,
1831 int instance_id = InstanceBot,
1832 const TypePtr* speculative = nullptr,
1833 int inline_depth = InlineDepthBottom,
1834 bool is_autobox_cache = false);
1835
1836 // Return a 'ptr' version of this type
1837 virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1838
1839 virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1840
1841 virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1842
1843 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1844 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1845
1846 virtual bool empty(void) const; // TRUE if type is vacuous
1847 virtual const TypePtr *add_offset( intptr_t offset ) const;
1848 virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1849 const TypeAryPtr* with_ary(const TypeAry* ary) const;
1850
1851 // Speculative type helper methods.
1852 virtual const TypeAryPtr* remove_speculative() const;
1853 virtual const Type* cleanup_speculative() const;
1854 virtual const TypePtr* with_inline_depth(int depth) const;
1855 virtual const TypePtr* with_instance_id(int instance_id) const;
1856
1857 // the core of the computation of the meet of 2 types
1858 virtual const Type *xmeet_helper(const Type *t) const;
1859 virtual const Type *xdual() const; // Compute dual right now.
1860
1861 // Inline type array properties
1862 const TypeAryPtr* cast_to_flat(bool flat) const;
1863 const TypeAryPtr* cast_to_not_flat(bool not_flat = true) const;
1864 const TypeAryPtr* cast_to_null_free(bool null_free) const;
1865 const TypeAryPtr* cast_to_not_null_free(bool not_null_free = true) const;
1866 const TypeAryPtr* update_properties(const TypeAryPtr* new_type) const;
1867 jint flat_layout_helper() const;
1868 int flat_elem_size() const;
1869 int flat_log_elem_size() const;
1870 jint max_flat_elements() const;
1871
1872 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1873 int stable_dimension() const;
1874
1875 const TypeAryPtr* cast_to_autobox_cache() const;
1876
1877 static jint max_array_length(BasicType etype);
1878
1879 int flat_offset() const;
1880 const Offset field_offset() const { return _field_offset; }
1881 const TypeAryPtr* with_field_offset(int offset) const;
1882 const TypePtr* add_field_offset_and_offset(intptr_t offset) const;
1883
1884 virtual bool can_be_inline_type() const { return false; }
1885 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1886
1887 virtual bool can_be_inline_array() const;
1888
1889 // Convenience common pre-built types.
1890 static const TypeAryPtr* BOTTOM;
1891 static const TypeAryPtr *RANGE;
1892 static const TypeAryPtr *OOPS;
1893 static const TypeAryPtr *NARROWOOPS;
1894 static const TypeAryPtr *BYTES;
1895 static const TypeAryPtr *SHORTS;
1896 static const TypeAryPtr *CHARS;
1897 static const TypeAryPtr *INTS;
1898 static const TypeAryPtr *LONGS;
1899 static const TypeAryPtr *FLOATS;
1900 static const TypeAryPtr *DOUBLES;
1901 static const TypeAryPtr *INLINES;
1902 // selects one of the above:
1903 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1904 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1905 return _array_body_type[elem];
1906 }
1907 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1908 // sharpen the type of an int which is used as an array size
1909 #ifndef PRODUCT
1910 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1911 #endif
1912 private:
1913 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1914 };
1915
1916 //------------------------------TypeMetadataPtr-------------------------------------
1917 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1918 class TypeMetadataPtr : public TypePtr {
1919 protected:
1920 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1921 // Do not allow interface-vs.-noninterface joins to collapse to top.
1922 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1923 public:
1924 virtual bool eq( const Type *t ) const;
1925 virtual uint hash() const; // Type specific hashing
1926 virtual bool singleton(void) const; // TRUE if type is a singleton
1927
1928 private:
1929 ciMetadata* _metadata;
1930
1931 public:
1932 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, Offset offset);
1933
1934 static const TypeMetadataPtr* make(ciMethod* m);
1935 static const TypeMetadataPtr* make(ciMethodData* m);
1936
1937 ciMetadata* metadata() const { return _metadata; }
1938
1939 virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1940
1941 virtual const TypePtr *add_offset( intptr_t offset ) const;
1942
1943 virtual const Type *xmeet( const Type *t ) const;
1944 virtual const Type *xdual() const; // Compute dual right now.
1945
1946 virtual intptr_t get_con() const;
1947
1948 // Convenience common pre-built types.
1949 static const TypeMetadataPtr *BOTTOM;
1950
1951 #ifndef PRODUCT
1952 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1953 #endif
1954 };
1955
1956 //------------------------------TypeKlassPtr-----------------------------------
1957 // Class of Java Klass pointers
1958 class TypeKlassPtr : public TypePtr {
1959 friend class TypeInstKlassPtr;
1960 friend class TypeAryKlassPtr;
1961 friend class TypePtr;
1962 protected:
1963 TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset);
1964
1965 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1966
1967 public:
1968 virtual bool eq( const Type *t ) const;
1969 virtual uint hash() const;
1970 virtual bool singleton(void) const; // TRUE if type is a singleton
1971
1972 protected:
1973
1974 ciKlass* _klass;
1975 const TypeInterfaces* _interfaces;
1976 const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1977 virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1978 virtual ciKlass* exact_klass_helper() const;
1979 virtual ciKlass* klass() const { return _klass; }
1980
1981 public:
1982
1983 bool is_java_subtype_of(const TypeKlassPtr* other) const {
1984 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1985 }
1986 bool is_same_java_type_as(const TypePtr* other) const {
1987 return is_same_java_type_as_helper(other->is_klassptr());
1988 }
1989
1990 bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1991 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1992 }
1993 virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1994 virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1995 virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1996
1997 // Exact klass, possibly an interface or an array of interface
1998 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1999 virtual bool klass_is_exact() const { return _ptr == Constant; }
2000
2001 static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
2002
2003 virtual bool is_loaded() const { return _klass->is_loaded(); }
2004
2005 virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
2006
2007 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
2008
2009 // corresponding pointer to instance, for a given class
2010 virtual const TypeOopPtr* as_exact_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
2011 // corresponding pointer to instances which subtype a given class
2012 virtual const TypeOopPtr* as_subtype_instance_type(bool klass_change = true) const = 0;
2013
2014 virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
2015 virtual const Type *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
2016 virtual const Type *xdual() const { ShouldNotReachHere(); return nullptr; }
2017
2018 virtual intptr_t get_con() const;
2019
2020 virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
2021
2022 virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
2023
2024 virtual const TypeKlassPtr* try_improve() const { return this; }
2025
2026 private:
2027 virtual bool is_meet_subtype_of(const TypePtr* other) const {
2028 return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
2029 }
2030
2031 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
2032 ShouldNotReachHere(); return false;
2033 }
2034
2035 virtual const TypeInterfaces* interfaces() const {
2036 return _interfaces;
2037 };
2038
2039 const TypeKlassPtr* is_reference_type(const Type* other) const {
2040 return other->isa_klassptr();
2041 }
2042
2043 const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
2044 return other->isa_aryklassptr();
2045 }
2046
2047 const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
2048 return other->isa_instklassptr();
2049 }
2050 };
2051
2052 // Instance klass pointer, mirrors TypeInstPtr
2053 class TypeInstKlassPtr : public TypeKlassPtr {
2054 // Can an instance of this class be in a flat array?
2055 const FlatInArray _flat_in_array;
2056
2057 TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array)
2058 : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset), _flat_in_array(flat_in_array) {
2059 assert(flat_in_array != Uninitialized, "must be set now");
2060 assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
2061 }
2062
2063 virtual bool must_be_exact() const;
2064
2065 public:
2066 // Instance klass ignoring any interface
2067 ciInstanceKlass* instance_klass() const {
2068 assert(!klass()->is_interface(), "");
2069 return klass()->as_instance_klass();
2070 }
2071
2072 bool might_be_an_array() const;
2073
2074 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
2075 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2076 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2077
2078 virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(klass_is_exact())); }
2079
2080 static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
2081 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
2082 return make(TypePtr::Constant, k, interfaces, Offset(0));
2083 }
2084
2085 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset,
2086 FlatInArray flat_in_array = Uninitialized);
2087
2088 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, Offset offset, FlatInArray flat_in_array = Uninitialized) {
2089 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
2090 return make(ptr, k, interfaces, offset, flat_in_array);
2091 }
2092
2093 virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
2094
2095 virtual const TypeInstKlassPtr *cast_to_exactness(bool klass_is_exact) const;
2096
2097 // corresponding pointer to instance, for a given class
2098 virtual const TypeInstPtr* as_exact_instance_type(bool klass_change = true) const;
2099 virtual const TypeInstPtr* as_subtype_instance_type(bool klass_change = true) const;
2100 virtual uint hash() const;
2101 virtual bool eq(const Type *t) const;
2102
2103
2104 virtual bool empty() const;
2105 virtual const TypePtr *add_offset( intptr_t offset ) const;
2106 virtual const Type *xmeet( const Type *t ) const;
2107 virtual const Type *xdual() const;
2108 virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
2109
2110 virtual const TypeKlassPtr* try_improve() const;
2111
2112 virtual FlatInArray flat_in_array() const { return _flat_in_array; }
2113
2114 FlatInArray dual_flat_in_array() const {
2115 return flat_in_array_dual[_flat_in_array];
2116 }
2117
2118 virtual bool can_be_inline_array() const;
2119
2120 // Convenience common pre-built types.
2121 static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
2122 static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
2123
2124 #ifndef PRODUCT
2125 virtual void dump2(Dict& d, uint depth, outputStream* st) const;
2126 #endif // PRODUCT
2127
2128 private:
2129 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2130 };
2131
2132 // Array klass pointer, mirrors TypeAryPtr
2133 class TypeAryKlassPtr : public TypeKlassPtr {
2134 friend class TypeInstKlassPtr;
2135 friend class Type;
2136 friend class TypePtr;
2137
2138 const Type *_elem;
2139 const bool _not_flat; // Array is never flat
2140 const bool _not_null_free; // Array is never null-free
2141 const bool _flat;
2142 const bool _null_free;
2143 const bool _atomic;
2144 const bool _refined_type;
2145
2146 static const TypeInterfaces* _array_interfaces;
2147 TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type)
2148 : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem), _not_flat(not_flat), _not_null_free(not_null_free), _flat(flat), _null_free(null_free), _atomic(atomic), _refined_type(refined_type) {
2149 assert(klass == nullptr || klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
2150 }
2151
2152 virtual ciKlass* exact_klass_helper() const;
2153 // Only guaranteed non null for array of basic types
2154 virtual ciKlass* klass() const;
2155
2156 virtual bool must_be_exact() const;
2157
2158 bool dual_flat() const {
2159 return _flat;
2160 }
2161
2162 bool meet_flat(bool other) const {
2163 return _flat && other;
2164 }
2165
2166 bool dual_null_free() const {
2167 return _null_free;
2168 }
2169
2170 bool meet_null_free(bool other) const {
2171 return _null_free && other;
2172 }
2173
2174 bool dual_atomic() const {
2175 return _atomic;
2176 }
2177
2178 bool meet_atomic(bool other) const {
2179 return _atomic && other;
2180 }
2181
2182 public:
2183
2184 // returns base element type, an instance klass (and not interface) for object arrays
2185 const Type* base_element_type(int& dims) const;
2186
2187 static const TypeAryKlassPtr* make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type);
2188
2189 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
2190 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2191 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2192
2193 bool is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
2194
2195 static const TypeAryKlassPtr* make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free, bool atomic, bool refined_type);
2196 static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
2197
2198 const TypeAryKlassPtr* cast_to_non_refined() const;
2199 const TypeAryKlassPtr* cast_to_default_refined() const;
2200 const TypeAryKlassPtr* cast_to_refined_array_klass_ptr(bool refined = true) const;
2201
2202 const Type *elem() const { return _elem; }
2203
2204 virtual bool eq(const Type *t) const;
2205 virtual uint hash() const; // Type specific hashing
2206
2207 virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
2208
2209 virtual const TypeAryKlassPtr* cast_to_exactness(bool klass_is_exact) const;
2210
2211 // corresponding pointer to instance, for a given class
2212 virtual const TypeAryPtr* as_exact_instance_type(bool klass_change = true) const;
2213 virtual const TypeAryPtr* as_subtype_instance_type(bool klass_change = true) const;
2214
2215 virtual const TypePtr *add_offset( intptr_t offset ) const;
2216 virtual const Type *xmeet( const Type *t ) const;
2217 virtual const Type *xdual() const; // Compute dual right now.
2218
2219 virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
2220
2221 virtual bool empty(void) const {
2222 return TypeKlassPtr::empty() || _elem->empty();
2223 }
2224
2225 bool is_flat() const { return _flat; }
2226 bool is_not_flat() const { return _not_flat; }
2227 bool is_null_free() const { return _null_free; }
2228 bool is_not_null_free() const { return _not_null_free; }
2229 bool is_atomic() const { return _atomic; }
2230 bool is_refined_type() const { return _refined_type; }
2231 virtual bool can_be_inline_array() const;
2232
2233 #ifndef PRODUCT
2234 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2235 #endif
2236 private:
2237 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2238 };
2239
2240 class TypeNarrowPtr : public Type {
2241 protected:
2242 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
2243
2244 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
2245 _ptrtype(ptrtype) {
2246 assert(ptrtype->offset() == 0 ||
2247 ptrtype->offset() == OffsetBot ||
2248 ptrtype->offset() == OffsetTop, "no real offsets");
2249 }
2250
2251 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2252 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
2348 }
2349
2350 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2351 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2352 }
2353
2354 public:
2355 static const TypeNarrowKlass *make( const TypePtr* type);
2356
2357 // static const TypeNarrowKlass *BOTTOM;
2358 static const TypeNarrowKlass *NULL_PTR;
2359
2360 #ifndef PRODUCT
2361 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2362 #endif
2363 };
2364
2365 //------------------------------TypeFunc---------------------------------------
2366 // Class of Array Types
2367 class TypeFunc : public Type {
2368 TypeFunc(const TypeTuple *domain_sig, const TypeTuple* domain_cc, const TypeTuple* range_sig, const TypeTuple* range_cc, bool scalarized_return)
2369 : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc), _scalarized_return(scalarized_return) {}
2370 virtual bool eq( const Type *t ) const;
2371 virtual uint hash() const; // Type specific hashing
2372 virtual bool singleton(void) const; // TRUE if type is a singleton
2373 virtual bool empty(void) const; // TRUE if type is vacuous
2374
2375 // Domains of inputs: inline type arguments are not passed by
2376 // reference, instead each field of the inline type is passed as an
2377 // argument. We maintain 2 views of the argument list here: one
2378 // based on the signature (with an inline type argument as a single
2379 // slot), one based on the actual calling convention (with a value
2380 // type argument as a list of its fields).
2381 const TypeTuple* const _domain_sig;
2382 const TypeTuple* const _domain_cc;
2383 // Range of results. Similar to domains: an inline type result can be
2384 // returned in registers in which case range_cc lists all fields and
2385 // is the actual calling convention.
2386 const TypeTuple* const _range_sig;
2387 const TypeTuple* const _range_cc;
2388 const bool _scalarized_return;
2389
2390 public:
2391 // Constants are shared among ADLC and VM
2392 enum { Control = AdlcVMDeps::Control,
2393 I_O = AdlcVMDeps::I_O,
2394 Memory = AdlcVMDeps::Memory,
2395 FramePtr = AdlcVMDeps::FramePtr,
2396 ReturnAdr = AdlcVMDeps::ReturnAdr,
2397 Parms = AdlcVMDeps::Parms
2398 };
2399
2400
2401 // Accessors:
2402 const TypeTuple* domain_sig() const { return _domain_sig; }
2403 const TypeTuple* domain_cc() const { return _domain_cc; }
2404 const TypeTuple* range_sig() const { return _range_sig; }
2405 const TypeTuple* range_cc() const { return _range_cc; }
2406
2407 static const TypeFunc* make(ciMethod* method, bool is_call = true, bool is_osr_compilation = false);
2408 static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
2409 const TypeTuple* range_sig, const TypeTuple* range_cc,
2410 bool scalarized_return = false);
2411 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2412
2413 virtual const Type *xmeet( const Type *t ) const;
2414 virtual const Type *xdual() const; // Compute dual right now.
2415
2416 BasicType return_type() const;
2417
2418 bool returns_inline_type_as_fields() const {
2419 // First condition is not sufficient because returned value class can be empty
2420 assert(_range_sig == _range_cc || _scalarized_return, "Only possible with scalarized return");
2421 return _scalarized_return;
2422 }
2423
2424 #ifndef PRODUCT
2425 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2426 #endif
2427 // Convenience common pre-built types.
2428 };
2429
2430 //------------------------------accessors--------------------------------------
2431 inline bool Type::is_ptr_to_narrowoop() const {
2432 #ifdef _LP64
2433 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2434 #else
2435 return false;
2436 #endif
2437 }
2438
2439 inline bool Type::is_ptr_to_narrowklass() const {
2440 #ifdef _LP64
2441 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2442 #else
2443 return false;
2680 }
2681
2682 inline const TypeNarrowOop* Type::make_narrowoop() const {
2683 return (_base == NarrowOop) ? is_narrowoop() :
2684 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2685 }
2686
2687 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2688 return (_base == NarrowKlass) ? is_narrowklass() :
2689 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2690 }
2691
2692 inline bool Type::is_floatingpoint() const {
2693 if( (_base == HalfFloatCon) || (_base == HalfFloatBot) ||
2694 (_base == FloatCon) || (_base == FloatBot) ||
2695 (_base == DoubleCon) || (_base == DoubleBot) )
2696 return true;
2697 return false;
2698 }
2699
2700 inline bool Type::is_inlinetypeptr() const {
2701 return isa_instptr() != nullptr && is_instptr()->instance_klass()->is_inlinetype();
2702 }
2703
2704 inline ciInlineKlass* Type::inline_klass() const {
2705 return make_ptr()->is_instptr()->instance_klass()->as_inline_klass();
2706 }
2707
2708 template <>
2709 inline const TypeInt* Type::cast<TypeInt>() const {
2710 return is_int();
2711 }
2712
2713 template <>
2714 inline const TypeLong* Type::cast<TypeLong>() const {
2715 return is_long();
2716 }
2717
2718 template <>
2719 inline const TypeInt* Type::try_cast<TypeInt>() const {
2720 return isa_int();
2721 }
2722
2723 template <>
2724 inline const TypeLong* Type::try_cast<TypeLong>() const {
2725 return isa_long();
2726 }
2727
2733
2734 // For type queries and asserts
2735 #define is_intptr_t is_long
2736 #define isa_intptr_t isa_long
2737 #define find_intptr_t_type find_long_type
2738 #define find_intptr_t_con find_long_con
2739 #define TypeX TypeLong
2740 #define Type_X Type::Long
2741 #define TypeX_X TypeLong::LONG
2742 #define TypeX_ZERO TypeLong::ZERO
2743 // For 'ideal_reg' machine registers
2744 #define Op_RegX Op_RegL
2745 // For phase->intcon variants
2746 #define MakeConX longcon
2747 #define ConXNode ConLNode
2748 // For array index arithmetic
2749 #define MulXNode MulLNode
2750 #define AndXNode AndLNode
2751 #define OrXNode OrLNode
2752 #define CmpXNode CmpLNode
2753 #define CmpUXNode CmpULNode
2754 #define SubXNode SubLNode
2755 #define LShiftXNode LShiftLNode
2756 // For object size computation:
2757 #define AddXNode AddLNode
2758 #define RShiftXNode RShiftLNode
2759 // For card marks and hashcodes
2760 #define URShiftXNode URShiftLNode
2761 // For pointer-sized accesses
2762 #define LoadXNode LoadLNode
2763 #define StoreXNode StoreLNode
2764 // Opcodes
2765 #define Op_LShiftX Op_LShiftL
2766 #define Op_AndX Op_AndL
2767 #define Op_AddX Op_AddL
2768 #define Op_SubX Op_SubL
2769 #define Op_XorX Op_XorL
2770 #define Op_URShiftX Op_URShiftL
2771 #define Op_LoadX Op_LoadL
2772 #define Op_StoreX Op_StoreL
2773 // conversions
2774 #define ConvI2X(x) ConvI2L(x)
2775 #define ConvL2X(x) (x)
2776 #define ConvX2I(x) ConvL2I(x)
2777 #define ConvX2L(x) (x)
2778 #define ConvX2UL(x) (x)
2779
2780 #else
2781
2782 // For type queries and asserts
2783 #define is_intptr_t is_int
2784 #define isa_intptr_t isa_int
2785 #define find_intptr_t_type find_int_type
2786 #define find_intptr_t_con find_int_con
2787 #define TypeX TypeInt
2788 #define Type_X Type::Int
2789 #define TypeX_X TypeInt::INT
2790 #define TypeX_ZERO TypeInt::ZERO
2791 // For 'ideal_reg' machine registers
2792 #define Op_RegX Op_RegI
2793 // For phase->intcon variants
2794 #define MakeConX intcon
2795 #define ConXNode ConINode
2796 // For array index arithmetic
2797 #define MulXNode MulINode
2798 #define AndXNode AndINode
2799 #define OrXNode OrINode
2800 #define CmpXNode CmpINode
2801 #define CmpUXNode CmpUNode
2802 #define SubXNode SubINode
2803 #define LShiftXNode LShiftINode
2804 // For object size computation:
2805 #define AddXNode AddINode
2806 #define RShiftXNode RShiftINode
2807 // For card marks and hashcodes
2808 #define URShiftXNode URShiftINode
2809 // For pointer-sized accesses
2810 #define LoadXNode LoadINode
2811 #define StoreXNode StoreINode
2812 // Opcodes
2813 #define Op_LShiftX Op_LShiftI
2814 #define Op_AndX Op_AndI
2815 #define Op_AddX Op_AddI
2816 #define Op_SubX Op_SubI
2817 #define Op_XorX Op_XorI
2818 #define Op_URShiftX Op_URShiftI
2819 #define Op_LoadX Op_LoadI
2820 #define Op_StoreX Op_StoreI
2821 // conversions
2822 #define ConvI2X(x) (x)
2823 #define ConvL2X(x) ConvL2I(x)
2824 #define ConvX2I(x) (x)
2825 #define ConvX2L(x) ConvI2L(x)
2826 #define ConvX2UL(x) ConvI2UL(x)
2827
2828 #endif
2829
2830 #endif // SHARE_OPTO_TYPE_HPP
|