1 /* 2 * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #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; 52 class TypeInt; 53 class TypeLong; 54 class TypeNarrowPtr; 55 class TypeNarrowOop; 56 class TypeNarrowKlass; 57 class TypeAry; 58 class TypeTuple; 59 class TypeVect; 60 class TypeVectA; 61 class TypeVectS; 62 class TypeVectD; 63 class TypeVectX; 64 class TypeVectY; 65 class TypeVectZ; 66 class TypePVectMask; 67 class TypePtr; 68 class TypeRawPtr; 69 class TypeOopPtr; 70 class TypeInstPtr; 71 class TypeAryPtr; 72 class TypeKlassPtr; 73 class TypeInstKlassPtr; 74 class TypeAryKlassPtr; 75 class TypeMetadataPtr; 76 class VerifyMeet; 77 78 template <class T, class U> 79 class TypeIntPrototype; 80 81 //------------------------------Type------------------------------------------- 82 // Basic Type object, represents a set of primitive Values. 83 // Types are hash-cons'd into a private class dictionary, so only one of each 84 // different kind of Type exists. Types are never modified after creation, so 85 // all their interesting fields are constant. 86 class Type { 87 88 public: 89 enum TYPES { 90 Bad=0, // Type check 91 Control, // Control of code (not in lattice) 92 Top, // Top of the lattice 93 Int, // Integer range (lo-hi) 94 Long, // Long integer range (lo-hi) 95 Half, // Placeholder half of doubleword 96 NarrowOop, // Compressed oop pointer 97 NarrowKlass, // Compressed klass pointer 98 99 Tuple, // Method signature or object layout 100 Array, // Array types 101 102 Interfaces, // Set of implemented interfaces for oop types 103 104 VectorMask, // Vector predicate/mask type 105 VectorA, // (Scalable) Vector types for vector length agnostic 106 VectorS, // 32bit Vector types 107 VectorD, // 64bit Vector types 108 VectorX, // 128bit Vector types 109 VectorY, // 256bit Vector types 110 VectorZ, // 512bit Vector types 111 112 AnyPtr, // Any old raw, klass, inst, or array pointer 113 RawPtr, // Raw (non-oop) pointers 114 OopPtr, // Any and all Java heap entities 115 InstPtr, // Instance pointers (non-array objects) 116 AryPtr, // Array pointers 117 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.) 118 119 MetadataPtr, // Generic metadata 120 KlassPtr, // Klass pointers 121 InstKlassPtr, 122 AryKlassPtr, 123 124 Function, // Function signature 125 Abio, // Abstract I/O 126 Return_Address, // Subroutine return address 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 ); 167 // Structural equality check. Assumes that equals() has already compared 168 // the _base types and thus knows it can cast 't' appropriately. 169 virtual bool eq( const Type *t ) const; 170 171 // Top-level hash-table of types 172 static Dict *type_dict() { 173 return Compile::current()->type_dict(); 174 } 175 176 // DUAL operation: reflect around lattice centerline. Used instead of 177 // join to ensure my lattice is symmetric up and down. Dual is computed 178 // lazily, on demand, and cached in _dual. 179 const Type *_dual; // Cached dual value 180 181 182 const Type *meet_helper(const Type *t, bool include_speculative) const; 183 void check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const NOT_DEBUG_RETURN; 184 185 protected: 186 // Each class of type is also identified by its base. 187 const TYPES _base; // Enum of Types type 188 189 Type( TYPES t ) : _dual(nullptr), _base(t) {} // Simple types 190 // ~Type(); // Use fast deallocation 191 const Type *hashcons(); // Hash-cons the type 192 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 193 const Type *join_helper(const Type *t, bool include_speculative) const { 194 assert_type_verify_empty(); 195 return dual()->meet_helper(t->dual(), include_speculative)->dual(); 196 } 197 198 void assert_type_verify_empty() const NOT_DEBUG_RETURN; 199 200 public: 201 202 inline void* operator new( size_t x ) throw() { 203 Compile* compile = Compile::current(); 204 compile->set_type_last_size(x); 205 return compile->type_arena()->AmallocWords(x); 206 } 207 inline void operator delete( void* ptr ) { 208 Compile* compile = Compile::current(); 209 compile->type_arena()->Afree(ptr,compile->type_last_size()); 210 } 211 212 // Initialize the type system for a particular compilation. 213 static void Initialize(Compile* compile); 214 215 // Initialize the types shared by all compilations. 216 static void Initialize_shared(Compile* compile); 217 218 TYPES base() const { 219 assert(_base > Bad && _base < lastype, "sanity"); 220 return _base; 221 } 222 223 // Create a new hash-consd type 224 static const Type *make(enum TYPES); 225 // Test for equivalence of types 226 static bool equals(const Type* t1, const Type* t2); 227 // Test for higher or equal in lattice 228 // Variant that drops the speculative part of the types 229 bool higher_equal(const Type* t) const { 230 return equals(meet(t), t->remove_speculative()); 231 } 232 // Variant that keeps the speculative part of the types 233 bool higher_equal_speculative(const Type* t) const { 234 return equals(meet_speculative(t), t); 235 } 236 237 // MEET operation; lower in lattice. 238 // Variant that drops the speculative part of the types 239 const Type *meet(const Type *t) const { 240 return meet_helper(t, false); 241 } 242 // Variant that keeps the speculative part of the types 243 const Type *meet_speculative(const Type *t) const { 244 return meet_helper(t, true)->cleanup_speculative(); 245 } 246 // WIDEN: 'widens' for Ints and other range types 247 virtual const Type *widen( const Type *old, const Type* limit ) const { return this; } 248 // NARROW: complement for widen, used by pessimistic phases 249 virtual const Type *narrow( const Type *old ) const { return this; } 250 251 // DUAL operation: reflect around lattice centerline. Used instead of 252 // join to ensure my lattice is symmetric up and down. 253 const Type *dual() const { return _dual; } 254 255 // Compute meet dependent on base type 256 virtual const Type *xmeet( const Type *t ) const; 257 virtual const Type *xdual() const; // Compute dual right now. 258 259 // JOIN operation; higher in lattice. Done by finding the dual of the 260 // meet of the dual of the 2 inputs. 261 // Variant that drops the speculative part of the types 262 const Type *join(const Type *t) const { 263 return join_helper(t, false); 264 } 265 // Variant that keeps the speculative part of the types 266 const Type *join_speculative(const Type *t) const { 267 return join_helper(t, true)->cleanup_speculative(); 268 } 269 270 // Modified version of JOIN adapted to the needs Node::Value. 271 // Normalizes all empty values to TOP. Does not kill _widen bits. 272 // Variant that drops the speculative part of the types 273 const Type *filter(const Type *kills) const { 274 return filter_helper(kills, false); 275 } 276 // Variant that keeps the speculative part of the types 277 const Type *filter_speculative(const Type *kills) const { 278 return filter_helper(kills, true)->cleanup_speculative(); 279 } 280 281 // Returns true if this pointer points at memory which contains a 282 // compressed oop references. 283 bool is_ptr_to_narrowoop() const; 284 bool is_ptr_to_narrowklass() const; 285 286 // Convenience access 287 short geth() const; 288 virtual float getf() const; 289 double getd() const; 290 291 // This has the same semantics as std::dynamic_cast<TypeClass*>(this) 292 template <typename TypeClass> 293 const TypeClass* try_cast() const; 294 295 const TypeInt *is_int() const; 296 const TypeInt *isa_int() const; // Returns null if not an Int 297 const TypeInteger* is_integer(BasicType bt) const; 298 const TypeInteger* isa_integer(BasicType bt) const; 299 const TypeLong *is_long() const; 300 const TypeLong *isa_long() const; // Returns null if not a Long 301 const TypeD *isa_double() const; // Returns null if not a Double{Top,Con,Bot} 302 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon 303 const TypeD *isa_double_constant() const; // Returns null if not a DoubleCon 304 const TypeH *isa_half_float() const; // Returns null if not a HalfFloat{Top,Con,Bot} 305 const TypeH *is_half_float_constant() const; // Asserts it is a HalfFloatCon 306 const TypeH *isa_half_float_constant() const; // Returns null if not a HalfFloatCon 307 const TypeF *isa_float() const; // Returns null if not a Float{Top,Con,Bot} 308 const TypeF *is_float_constant() const; // Asserts it is a FloatCon 309 const TypeF *isa_float_constant() const; // Returns null if not a FloatCon 310 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer 311 const TypeAry *is_ary() const; // Array, NOT array pointer 312 const TypeAry *isa_ary() const; // Returns null of not ary 313 const TypeVect *is_vect() const; // Vector 314 const TypeVect *isa_vect() const; // Returns null if not a Vector 315 const TypePVectMask *is_pvectmask() const; // Predicate/Mask Vector 316 const TypePVectMask *isa_pvectmask() const; // Returns null if not a Vector Predicate/Mask 317 const TypePtr *is_ptr() const; // Asserts it is a ptr type 318 const TypePtr *isa_ptr() const; // Returns null if not ptr type 319 const TypeRawPtr *isa_rawptr() const; // NOT Java oop 320 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr 321 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer 322 const TypeNarrowOop *isa_narrowoop() const; // Returns null if not oop ptr type 323 const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer 324 const TypeNarrowKlass *isa_narrowklass() const;// Returns null if not oop ptr type 325 const TypeOopPtr *isa_oopptr() const; // Returns null if not oop ptr type 326 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer 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; 367 368 // TRUE if type is a singleton 369 virtual bool singleton(void) const; 370 371 // TRUE if type is above the lattice centerline, and is therefore vacuous 372 virtual bool empty(void) const; 373 374 // Return a hash for this type. The hash function is public so ConNode 375 // (constants) can hash on their constant, which is represented by a Type. 376 virtual uint hash() const; 377 378 // Map ideal registers (machine types) to ideal types 379 static const Type *mreg2type[]; 380 381 // Printing, statistics 382 #ifndef PRODUCT 383 void dump_on(outputStream *st) const; 384 void dump() const { 385 dump_on(tty); 386 } 387 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 388 static void dump_stats(); 389 // Groups of types, for debugging and visualization only. 390 enum class Category { 391 Data, 392 Memory, 393 Mixed, // Tuples with types of different categories. 394 Control, 395 Other, // {Type::Top, Type::Abio, Type::Bottom}. 396 Undef // {Type::Bad, Type::lastype}, for completeness. 397 }; 398 // Return the category of this type. 399 Category category() const; 400 // Check recursively in tuples. 401 bool has_category(Category cat) const; 402 403 static const char* str(const Type* t); 404 #endif // !PRODUCT 405 void typerr(const Type *t) const; // Mixing types error 406 407 // Create basic type 408 static const Type* get_const_basic_type(BasicType type) { 409 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != nullptr, "bad type"); 410 return _const_basic_type[type]; 411 } 412 413 // For two instance arrays of same dimension, return the base element types. 414 // Otherwise or if the arrays have different dimensions, return null. 415 static void get_arrays_base_elements(const Type *a1, const Type *a2, 416 const TypeInstPtr **e1, const TypeInstPtr **e2); 417 418 // Mapping to the array element's basic type. 419 BasicType array_element_basic_type() const; 420 421 enum InterfaceHandling { 422 trust_interfaces, 423 ignore_interfaces 424 }; 425 // Create standard type for a ciType: 426 static const Type* get_const_type(ciType* type, InterfaceHandling interface_handling = ignore_interfaces); 427 428 // Create standard zero value: 429 static const Type* get_zero_type(BasicType type) { 430 assert((uint)type <= T_CONFLICT && _zero_type[type] != nullptr, "bad type"); 431 return _zero_type[type]; 432 } 433 434 // Report if this is a zero value (not top). 435 bool is_zero_type() const { 436 BasicType type = basic_type(); 437 if (type == T_VOID || type >= T_CONFLICT) 438 return false; 439 else 440 return (this == _zero_type[type]); 441 } 442 443 // Convenience common pre-built types. 444 static const Type *ABIO; 445 static const Type *BOTTOM; 446 static const Type *CONTROL; 447 static const Type *DOUBLE; 448 static const Type *FLOAT; 449 static const Type *HALF_FLOAT; 450 static const Type *HALF; 451 static const Type *MEMORY; 452 static const Type *MULTI; 453 static const Type *RETURN_ADDRESS; 454 static const Type *TOP; 455 456 // Mapping from compiler type to VM BasicType 457 BasicType basic_type() const { return _type_info[_base].basic_type; } 458 uint ideal_reg() const { return _type_info[_base].ideal_reg; } 459 const char* msg() const { return _type_info[_base].msg; } 460 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; } 461 462 // Mapping from CI type system to compiler type: 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: 503 // support arrays 504 static const Type* _zero_type[T_CONFLICT+1]; 505 static const Type* _const_basic_type[T_CONFLICT+1]; 506 }; 507 508 //------------------------------TypeF------------------------------------------ 509 // Class of Float-Constant Types. 510 class TypeF : public Type { 511 TypeF( float f ) : Type(FloatCon), _f(f) {}; 512 public: 513 virtual bool eq( const Type *t ) const; 514 virtual uint hash() const; // Type specific hashing 515 virtual bool singleton(void) const; // TRUE if type is a singleton 516 virtual bool empty(void) const; // TRUE if type is vacuous 517 public: 518 const float _f; // Float constant 519 520 static const TypeF *make(float f); 521 522 virtual bool is_finite() const; // Has a finite value 523 virtual bool is_nan() const; // Is not a number (NaN) 524 525 virtual const Type *xmeet( const Type *t ) const; 526 virtual const Type *xdual() const; // Compute dual right now. 527 // Convenience common pre-built types. 528 static const TypeF *MAX; 529 static const TypeF *MIN; 530 static const TypeF *ZERO; // positive zero only 531 static const TypeF *ONE; 532 static const TypeF *POS_INF; 533 static const TypeF *NEG_INF; 534 #ifndef PRODUCT 535 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 536 #endif 537 }; 538 539 // Class of Half Float-Constant Types. 540 class TypeH : public Type { 541 TypeH(short f) : Type(HalfFloatCon), _f(f) {}; 542 public: 543 virtual bool eq(const Type* t) const; 544 virtual uint hash() const; // Type specific hashing 545 virtual bool singleton(void) const; // TRUE if type is a singleton 546 virtual bool empty(void) const; // TRUE if type is vacuous 547 public: 548 const short _f; // Half Float constant 549 550 static const TypeH* make(float f); 551 static const TypeH* make(short f); 552 553 virtual bool is_finite() const; // Has a finite value 554 virtual bool is_nan() const; // Is not a number (NaN) 555 556 virtual float getf() const; 557 virtual const Type* xmeet(const Type* t) const; 558 virtual const Type* xdual() const; // Compute dual right now. 559 // Convenience common pre-built types. 560 static const TypeH* MAX; 561 static const TypeH* MIN; 562 static const TypeH* ZERO; // positive zero only 563 static const TypeH* ONE; 564 static const TypeH* POS_INF; 565 static const TypeH* NEG_INF; 566 #ifndef PRODUCT 567 virtual void dump2(Dict &d, uint depth, outputStream* st) const; 568 #endif 569 }; 570 571 //------------------------------TypeD------------------------------------------ 572 // Class of Double-Constant Types. 573 class TypeD : public Type { 574 TypeD( double d ) : Type(DoubleCon), _d(d) {}; 575 public: 576 virtual bool eq( const Type *t ) const; 577 virtual uint hash() const; // Type specific hashing 578 virtual bool singleton(void) const; // TRUE if type is a singleton 579 virtual bool empty(void) const; // TRUE if type is vacuous 580 public: 581 const double _d; // Double constant 582 583 static const TypeD *make(double d); 584 585 virtual bool is_finite() const; // Has a finite value 586 virtual bool is_nan() const; // Is not a number (NaN) 587 588 virtual const Type *xmeet( const Type *t ) const; 589 virtual const Type *xdual() const; // Compute dual right now. 590 // Convenience common pre-built types. 591 static const TypeD *MAX; 592 static const TypeD *MIN; 593 static const TypeD *ZERO; // positive zero only 594 static const TypeD *ONE; 595 static const TypeD *POS_INF; 596 static const TypeD *NEG_INF; 597 #ifndef PRODUCT 598 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 599 #endif 600 }; 601 602 class TypeInteger : public Type { 603 protected: 604 TypeInteger(TYPES t, int w, bool dual) : Type(t), _is_dual(dual), _widen(w) {} 605 606 // Denote that a set is a dual set. 607 // Dual sets are only used to compute the join of 2 sets, and not used 608 // outside. 609 const bool _is_dual; 610 611 public: 612 const short _widen; // Limit on times we widen this sucker 613 614 virtual jlong hi_as_long() const = 0; 615 virtual jlong lo_as_long() const = 0; 616 jlong get_con_as_long(BasicType bt) const; 617 bool is_con() const { return lo_as_long() == hi_as_long(); } 618 virtual short widen_limit() const { return _widen; } 619 620 static const TypeInteger* make(jlong lo, jlong hi, int w, BasicType bt); 621 static const TypeInteger* make(jlong con, BasicType bt); 622 623 static const TypeInteger* bottom(BasicType type); 624 static const TypeInteger* zero(BasicType type); 625 static const TypeInteger* one(BasicType type); 626 static const TypeInteger* minus_1(BasicType type); 627 }; 628 629 /** 630 * Definition: 631 * 632 * A TypeInt represents a set of non-empty jint values. A jint v is an element 633 * of a TypeInt iff: 634 * 635 * v >= _lo && v <= _hi && 636 * juint(v) >= _ulo && juint(v) <= _uhi && 637 * _bits.is_satisfied_by(v) 638 * 639 * Multiple sets of parameters can represent the same set. 640 * E.g: consider 2 TypeInt t1, t2 641 * 642 * t1._lo = 2, t1._hi = 7, t1._ulo = 0, t1._uhi = 5, t1._bits._zeros = 0x00000000, t1._bits._ones = 0x1 643 * t2._lo = 3, t2._hi = 5, t2._ulo = 3, t2._uhi = 5, t2._bits._zeros = 0xFFFFFFF8, t2._bits._ones = 0x1 644 * 645 * Then, t1 and t2 both represent the set {3, 5}. We can also see that the 646 * constraints of t2 are the tightest possible. I.e there exists no TypeInt t3 647 * which also represents {3, 5} such that any of these would be true: 648 * 649 * 1) t3._lo > t2._lo 650 * 2) t3._hi < t2._hi 651 * 3) t3._ulo > t2._ulo 652 * 4) t3._uhi < t2._uhi 653 * 5) (t3._bits._zeros &~ t2._bis._zeros) != 0 654 * 6) (t3._bits._ones &~ t2._bits._ones) != 0 655 * 656 * The 5-th condition mean that the subtraction of the bitsets represented by 657 * t3._bits._zeros and t2._bits._zeros is not empty, which means that the 658 * bits in t3._bits._zeros is not a subset of those in t2._bits._zeros, the 659 * same applies to _bits._ones 660 * 661 * To simplify reasoning about the types in optimizations, we canonicalize 662 * every TypeInt to its tightest form, already at construction. E.g a TypeInt 663 * t with t._lo < 0 will definitely contain negative values. It also makes it 664 * trivial to determine if a TypeInt instance is a subset of another. 665 * 666 * Lemmas: 667 * 668 * 1. Since every TypeInt instance is non-empty and canonicalized, all the 669 * bounds must also be elements of such TypeInt. Or else, we can tighten the 670 * bounds by narrowing it by one, which contradicts the assumption of the 671 * TypeInt being canonical. 672 * 673 * 2. 674 * 2.1. _lo <= jint(_ulo) 675 * 2.2. _lo <= _hi 676 * 2.3. _lo <= jint(_uhi) 677 * 2.4. _ulo <= juint(_lo) 678 * 2.5. _ulo <= juint(_hi) 679 * 2.6. _ulo <= _uhi 680 * 2.7. _hi >= _lo 681 * 2.8. _hi >= jint(_ulo) 682 * 2.9. _hi >= jint(_uhi) 683 * 2.10. _uhi >= juint(_lo) 684 * 2.11. _uhi >= _ulo 685 * 2.12. _uhi >= juint(_hi) 686 * 687 * Proof of lemma 2: 688 * 689 * 2.1. _lo <= jint(_ulo): 690 * According the lemma 1, _ulo is an element of the TypeInt, so in the 691 * signed domain, it must not be less than the smallest element of that 692 * TypeInt, which is _lo. Which means that _lo <= _ulo in the signed 693 * domain, or in a more programmatical way, _lo <= jint(_ulo). 694 * 2.2. _lo <= _hi: 695 * According the lemma 1, _hi is an element of the TypeInt, so in the 696 * signed domain, it must not be less than the smallest element of that 697 * TypeInt, which is _lo. Which means that _lo <= _hi. 698 * 699 * The other inequalities can be proved in a similar manner. 700 * 701 * 3. Given 2 jint values x, y where either both >= 0 or both < 0. Then: 702 * 703 * x <= y iff juint(x) <= juint(y) 704 * I.e. x <= y in the signed domain iff x <= y in the unsigned domain 705 * 706 * 4. Either _lo == jint(_ulo) and _hi == jint(_uhi), or each element of a 707 * TypeInt lies in either interval [_lo, jint(_uhi)] or [jint(_ulo), _hi] 708 * (note that these intervals are disjoint in this case). 709 * 710 * Proof of lemma 4: 711 * 712 * For a TypeInt t, there are 3 possible cases: 713 * 714 * a. t._lo >= 0, we have: 715 * 716 * 0 <= t_lo <= jint(t._ulo) (lemma 2.1) 717 * juint(t._lo) <= juint(jint(t._ulo)) (lemma 3) 718 * == t._ulo (juint(jint(v)) == v with juint v) 719 * <= juint(t._lo) (lemma 2.4) 720 * 721 * Which means that t._lo == jint(t._ulo). 722 * 723 * Furthermore, 724 * 725 * 0 <= t._lo <= t._hi (lemma 2.2) 726 * 0 <= t._lo <= jint(t._uhi) (lemma 2.3) 727 * t._hi >= jint(t._uhi) (lemma 2.9) 728 * 729 * juint(t._hi) >= juint(jint(t._uhi)) (lemma 3) 730 * == t._uhi (juint(jint(v)) == v with juint v) 731 * >= juint(t._hi) (lemma 2.12) 732 * 733 * Which means that t._hi == jint(t._uhi). 734 * In this case, t._lo == jint(t._ulo) and t._hi == jint(t._uhi) 735 * 736 * b. t._hi < 0. Similarly, we can conclude that: 737 * t._lo == jint(t._ulo) and t._hi == jint(t._uhi) 738 * 739 * c. t._lo < 0, t._hi >= 0. 740 * 741 * Since t._ulo <= juint(t._hi) (lemma 2.5), we must have jint(t._ulo) >= 0 742 * because all negative values is larger than all non-negative values in the 743 * unsigned domain. 744 * 745 * Since t._uhi >= juint(t._lo) (lemma 2.10), we must have jint(t._uhi) < 0 746 * similar to the reasoning above. 747 * 748 * In this case, each element of t belongs to either [t._lo, jint(t._uhi)] or 749 * [jint(t._ulo), t._hi]. 750 * 751 * Below is an illustration of the TypeInt in this case, the intervals that 752 * the elements can be in are marked using the = symbol. Note how the 753 * negative range in the signed domain wrap around in the unsigned domain. 754 * 755 * Signed: 756 * -----lo=========uhi---------0--------ulo==========hi----- 757 * Unsigned: 758 * 0--------ulo==========hi----------lo=========uhi--------- 759 * 760 * This property is useful for our analysis of TypeInt values. Additionally, 761 * it can be seen that _lo and jint(_uhi) are both < 0 or both >= 0, and the 762 * same applies to jint(_ulo) and _hi. 763 * 764 * We call [_lo, jint(_uhi)] and [jint(_ulo), _hi] "simple intervals". Then, 765 * a TypeInt consists of 2 simple intervals, each of which has its bounds 766 * being both >= 0 or both < 0. If both simple intervals lie in the same half 767 * of the integer domain, they must be the same (i.e _lo == jint(_ulo) and 768 * _hi == jint(_uhi)). Otherwise, [_lo, jint(_uhi)] must lie in the negative 769 * half and [jint(_ulo), _hi] must lie in the non-negative half of the signed 770 * domain (equivalently, [_lo, jint(_uhi)] must lie in the upper half and 771 * [jint(_ulo), _hi] must lie in the lower half of the unsigned domain). 772 */ 773 class TypeInt : public TypeInteger { 774 private: 775 TypeInt(const TypeIntPrototype<jint, juint>& t, int w, bool dual); 776 static const Type* make_or_top(const TypeIntPrototype<jint, juint>& t, int widen, bool dual); 777 778 friend class TypeIntHelper; 779 780 protected: 781 virtual const Type* filter_helper(const Type* kills, bool include_speculative) const; 782 783 public: 784 typedef jint NativeType; 785 virtual bool eq(const Type* t) const; 786 virtual uint hash() const; // Type specific hashing 787 virtual bool singleton(void) const; // TRUE if type is a singleton 788 virtual bool empty(void) const; // TRUE if type is vacuous 789 // A value is in the set represented by this TypeInt if it satisfies all 790 // the below constraints, see contains(jint) 791 const jint _lo, _hi; // Lower bound, upper bound in the signed domain 792 const juint _ulo, _uhi; // Lower bound, upper bound in the unsigned domain 793 const KnownBits<juint> _bits; 794 795 static const TypeInt* make(jint con); 796 // must always specify w 797 static const TypeInt* make(jint lo, jint hi, int widen); 798 static const Type* make_or_top(const TypeIntPrototype<jint, juint>& t, int widen); 799 static const TypeInt* make(const TypeIntPrototype<jint, juint>& t, int widen) { return make_or_top(t, widen)->is_int(); } 800 static const TypeInt* make(const TypeIntMirror<jint, juint>& t, int widen) { 801 return (new TypeInt(TypeIntPrototype<jint, juint>{{t._lo, t._hi}, {t._ulo, t._uhi}, t._bits}, widen, false))->hashcons()->is_int(); 802 } 803 804 // Check for single integer 805 bool is_con() const { return _lo == _hi; } 806 bool is_con(jint i) const { return is_con() && _lo == i; } 807 jint get_con() const { assert(is_con(), ""); return _lo; } 808 // Check if a jint/TypeInt is a subset of this TypeInt (i.e. all elements of the 809 // argument are also elements of this type) 810 bool contains(jint i) const; 811 bool contains(const TypeInt* t) const; 812 813 #ifdef ASSERT 814 // Check whether t is a proper subset (i.e. a subset that is not equal to the superset) of this 815 bool strictly_contains(const TypeInt* t) const; 816 #endif // ASSERT 817 818 virtual bool is_finite() const; // Has a finite value 819 820 virtual const Type* xmeet(const Type* t) const; 821 virtual const Type* xdual() const; // Compute dual right now. 822 virtual const Type* widen(const Type* t, const Type* limit_type) const; 823 virtual const Type* narrow(const Type* t) const; 824 825 virtual jlong hi_as_long() const { return _hi; } 826 virtual jlong lo_as_long() const { return _lo; } 827 828 // Do not kill _widen bits. 829 // Convenience common pre-built types. 830 static const TypeInt* MAX; 831 static const TypeInt* MIN; 832 static const TypeInt* MINUS_1; 833 static const TypeInt* ZERO; 834 static const TypeInt* ONE; 835 static const TypeInt* BOOL; 836 static const TypeInt* CC; 837 static const TypeInt* CC_LT; // [-1] == MINUS_1 838 static const TypeInt* CC_GT; // [1] == ONE 839 static const TypeInt* CC_EQ; // [0] == ZERO 840 static const TypeInt* CC_NE; // [-1, 1] 841 static const TypeInt* CC_LE; // [-1,0] 842 static const TypeInt* CC_GE; // [0,1] == BOOL (!) 843 static const TypeInt* BYTE; 844 static const TypeInt* UBYTE; 845 static const TypeInt* CHAR; 846 static const TypeInt* SHORT; 847 static const TypeInt* NON_ZERO; 848 static const TypeInt* POS; 849 static const TypeInt* POS1; 850 static const TypeInt* INT; 851 static const TypeInt* SYMINT; // symmetric range [-max_jint..max_jint] 852 static const TypeInt* TYPE_DOMAIN; // alias for TypeInt::INT 853 854 static const TypeInt* as_self(const Type* t) { return t->is_int(); } 855 #ifndef PRODUCT 856 virtual void dump2(Dict& d, uint depth, outputStream* st) const; 857 void dump_verbose() const; 858 #endif 859 }; 860 861 // Similar to TypeInt 862 class TypeLong : public TypeInteger { 863 private: 864 TypeLong(const TypeIntPrototype<jlong, julong>& t, int w, bool dual); 865 static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual); 866 867 friend class TypeIntHelper; 868 869 protected: 870 // Do not kill _widen bits. 871 virtual const Type* filter_helper(const Type* kills, bool include_speculative) const; 872 public: 873 typedef jlong NativeType; 874 virtual bool eq( const Type *t ) const; 875 virtual uint hash() const; // Type specific hashing 876 virtual bool singleton(void) const; // TRUE if type is a singleton 877 virtual bool empty(void) const; // TRUE if type is vacuous 878 public: 879 // A value is in the set represented by this TypeLong if it satisfies all 880 // the below constraints, see contains(jlong) 881 const jlong _lo, _hi; // Lower bound, upper bound in the signed domain 882 const julong _ulo, _uhi; // Lower bound, upper bound in the unsigned domain 883 const KnownBits<julong> _bits; 884 885 static const TypeLong* make(jlong con); 886 // must always specify w 887 static const TypeLong* make(jlong lo, jlong hi, int widen); 888 static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen); 889 static const TypeLong* make(const TypeIntPrototype<jlong, julong>& t, int widen) { return make_or_top(t, widen)->is_long(); } 890 static const TypeLong* make(const TypeIntMirror<jlong, julong>& t, int widen) { 891 return (new TypeLong(TypeIntPrototype<jlong, julong>{{t._lo, t._hi}, {t._ulo, t._uhi}, t._bits}, widen, false))->hashcons()->is_long(); 892 } 893 894 // Check for single integer 895 bool is_con() const { return _lo == _hi; } 896 bool is_con(jlong i) const { return is_con() && _lo == i; } 897 jlong get_con() const { assert(is_con(), "" ); return _lo; } 898 // Check if a jlong/TypeLong is a subset of this TypeLong (i.e. all elements of the 899 // argument are also elements of this type) 900 bool contains(jlong i) const; 901 bool contains(const TypeLong* t) const; 902 903 #ifdef ASSERT 904 // Check whether t is a proper subset (i.e. a subset that is not equal to the superset) of this 905 bool strictly_contains(const TypeLong* t) const; 906 #endif // ASSERT 907 908 // Check for positive 32-bit value. 909 int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; } 910 911 virtual bool is_finite() const; // Has a finite value 912 913 virtual jlong hi_as_long() const { return _hi; } 914 virtual jlong lo_as_long() const { return _lo; } 915 916 virtual const Type* xmeet(const Type* t) const; 917 virtual const Type* xdual() const; // Compute dual right now. 918 virtual const Type* widen(const Type* t, const Type* limit_type) const; 919 virtual const Type* narrow(const Type* t) const; 920 // Convenience common pre-built types. 921 static const TypeLong* MAX; 922 static const TypeLong* MIN; 923 static const TypeLong* MINUS_1; 924 static const TypeLong* ZERO; 925 static const TypeLong* ONE; 926 static const TypeLong* NON_ZERO; 927 static const TypeLong* POS; 928 static const TypeLong* NEG; 929 static const TypeLong* LONG; 930 static const TypeLong* INT; // 32-bit subrange [min_jint..max_jint] 931 static const TypeLong* UINT; // 32-bit unsigned [0..max_juint] 932 static const TypeLong* TYPE_DOMAIN; // alias for TypeLong::LONG 933 934 // static convenience methods. 935 static const TypeLong* as_self(const Type* t) { return t->is_long(); } 936 937 #ifndef PRODUCT 938 virtual void dump2(Dict& d, uint, outputStream* st) const;// Specialized per-Type dumping 939 void dump_verbose() const; 940 #endif 941 }; 942 943 //------------------------------TypeTuple-------------------------------------- 944 // Class of Tuple Types, essentially type collections for function signatures 945 // and class layouts. It happens to also be a fast cache for the HotSpot 946 // signature types. 947 class TypeTuple : public Type { 948 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { } 949 950 const uint _cnt; // Count of fields 951 const Type ** const _fields; // Array of field types 952 953 public: 954 virtual bool eq( const Type *t ) const; 955 virtual uint hash() const; // Type specific hashing 956 virtual bool singleton(void) const; // TRUE if type is a singleton 957 virtual bool empty(void) const; // TRUE if type is vacuous 958 959 // Accessors: 960 uint cnt() const { return _cnt; } 961 const Type* field_at(uint i) const { 962 assert(i < _cnt, "oob"); 963 return _fields[i]; 964 } 965 void set_field_at(uint i, const Type* t) { 966 assert(i < _cnt, "oob"); 967 _fields[i] = t; 968 } 969 970 static const TypeTuple *make( uint cnt, const Type **fields ); 971 static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces); 972 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling); 973 974 // Subroutine call type with space allocated for argument types 975 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly 976 static const Type **fields( uint arg_cnt ); 977 978 virtual const Type *xmeet( const Type *t ) const; 979 virtual const Type *xdual() const; // Compute dual right now. 980 // Convenience common pre-built types. 981 static const TypeTuple *IFBOTH; 982 static const TypeTuple *IFFALSE; 983 static const TypeTuple *IFTRUE; 984 static const TypeTuple *IFNEITHER; 985 static const TypeTuple *LOOPBODY; 986 static const TypeTuple *MEMBAR; 987 static const TypeTuple *STORECONDITIONAL; 988 static const TypeTuple *START_I2C; 989 static const TypeTuple *INT_PAIR; 990 static const TypeTuple *LONG_PAIR; 991 static const TypeTuple *INT_CC_PAIR; 992 static const TypeTuple *LONG_CC_PAIR; 993 #ifndef PRODUCT 994 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 995 #endif 996 }; 997 998 //------------------------------TypeAry---------------------------------------- 999 // Class of Array Types 1000 class TypeAry : public Type { 1001 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array), 1002 _elem(elem), _size(size), _stable(stable) {} 1003 public: 1004 virtual bool eq( const Type *t ) const; 1005 virtual uint hash() const; // Type specific hashing 1006 virtual bool singleton(void) const; // TRUE if type is a singleton 1007 virtual bool empty(void) const; // TRUE if type is vacuous 1008 1009 private: 1010 const Type *_elem; // Element type of array 1011 const TypeInt *_size; // Elements in array 1012 const bool _stable; // Are elements @Stable? 1013 friend class TypeAryPtr; 1014 1015 public: 1016 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false); 1017 1018 virtual const Type *xmeet( const Type *t ) const; 1019 virtual const Type *xdual() const; // Compute dual right now. 1020 bool ary_must_be_exact() const; // true if arrays of such are never generic 1021 virtual const TypeAry* remove_speculative() const; 1022 virtual const Type* cleanup_speculative() const; 1023 #ifndef PRODUCT 1024 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 1025 #endif 1026 }; 1027 1028 //------------------------------TypeVect--------------------------------------- 1029 // Basic class of vector (mask) types. 1030 class TypeVect : public Type { 1031 const BasicType _elem_bt; // Vector's element type 1032 const uint _length; // Elements in vector (power of 2) 1033 1034 protected: 1035 TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t), 1036 _elem_bt(elem_bt), _length(length) {} 1037 1038 public: 1039 BasicType element_basic_type() const { return _elem_bt; } 1040 uint length() const { return _length; } 1041 uint length_in_bytes() const { 1042 return _length * type2aelembytes(element_basic_type()); 1043 } 1044 1045 virtual bool eq(const Type* t) const; 1046 virtual uint hash() const; // Type specific hashing 1047 virtual bool singleton(void) const; // TRUE if type is a singleton 1048 virtual bool empty(void) const; // TRUE if type is vacuous 1049 1050 static const TypeVect* make(const BasicType elem_bt, uint length, bool is_mask = false); 1051 static const TypeVect* makemask(const BasicType elem_bt, uint length); 1052 1053 virtual const Type* xmeet( const Type *t) const; 1054 virtual const Type* xdual() const; // Compute dual right now. 1055 1056 static const TypeVect* VECTA; 1057 static const TypeVect* VECTS; 1058 static const TypeVect* VECTD; 1059 static const TypeVect* VECTX; 1060 static const TypeVect* VECTY; 1061 static const TypeVect* VECTZ; 1062 static const TypeVect* VECTMASK; 1063 1064 #ifndef PRODUCT 1065 virtual void dump2(Dict& d, uint, outputStream* st) const; // Specialized per-Type dumping 1066 #endif 1067 }; 1068 1069 // TypeVect subclasses representing vectors or vector masks with "BVectMask" or "NVectMask" 1070 // layout (see vectornode.hpp for detailed notes on vector mask representations), mapped 1071 // to vector registers and distinguished by vector register size: 1072 // 1073 // - TypeVectA: Scalable vector type (variable size, e.g., AArch64 SVE, RISC-V RVV) 1074 // - TypeVectS: 32-bit vector type 1075 // - TypeVectD: 64-bit vector type 1076 // - TypeVectX: 128-bit vector type 1077 // - TypeVectY: 256-bit vector type 1078 // - TypeVectZ: 512-bit vector type 1079 class TypeVectA : public TypeVect { 1080 friend class TypeVect; 1081 TypeVectA(BasicType elem_bt, uint length) : TypeVect(VectorA, elem_bt, length) {} 1082 }; 1083 1084 class TypeVectS : public TypeVect { 1085 friend class TypeVect; 1086 TypeVectS(BasicType elem_bt, uint length) : TypeVect(VectorS, elem_bt, length) {} 1087 }; 1088 1089 class TypeVectD : public TypeVect { 1090 friend class TypeVect; 1091 TypeVectD(BasicType elem_bt, uint length) : TypeVect(VectorD, elem_bt, length) {} 1092 }; 1093 1094 class TypeVectX : public TypeVect { 1095 friend class TypeVect; 1096 TypeVectX(BasicType elem_bt, uint length) : TypeVect(VectorX, elem_bt, length) {} 1097 }; 1098 1099 class TypeVectY : public TypeVect { 1100 friend class TypeVect; 1101 TypeVectY(BasicType elem_bt, uint length) : TypeVect(VectorY, elem_bt, length) {} 1102 }; 1103 1104 class TypeVectZ : public TypeVect { 1105 friend class TypeVect; 1106 TypeVectZ(BasicType elem_bt, uint length) : TypeVect(VectorZ, elem_bt, length) {} 1107 }; 1108 1109 // Class of TypePVectMask, representing vector masks with "PVectMask" layout (see 1110 // vectornode.hpp for detailed notes on vector mask representations), mapped to 1111 // dedicated hardware predicate/mask registers. 1112 class TypePVectMask : public TypeVect { 1113 public: 1114 friend class TypeVect; 1115 TypePVectMask(BasicType elem_bt, uint length) : TypeVect(VectorMask, elem_bt, length) {} 1116 static const TypePVectMask* make(const BasicType elem_bt, uint length); 1117 }; 1118 1119 // Set of implemented interfaces. Referenced from TypeOopPtr and TypeKlassPtr. 1120 class TypeInterfaces : public Type { 1121 private: 1122 GrowableArrayFromArray<ciInstanceKlass*> _interfaces; 1123 uint _hash; 1124 ciInstanceKlass* _exact_klass; 1125 DEBUG_ONLY(bool _initialized;) 1126 1127 void initialize(); 1128 1129 void verify() const NOT_DEBUG_RETURN; 1130 void compute_hash(); 1131 void compute_exact_klass(); 1132 1133 TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces); 1134 1135 NONCOPYABLE(TypeInterfaces); 1136 public: 1137 static const TypeInterfaces* make(GrowableArray<ciInstanceKlass*>* interfaces = nullptr); 1138 bool eq(const Type* other) const; 1139 bool eq(ciInstanceKlass* k) const; 1140 uint hash() const; 1141 const Type *xdual() const; 1142 void dump(outputStream* st) const; 1143 const TypeInterfaces* union_with(const TypeInterfaces* other) const; 1144 const TypeInterfaces* intersection_with(const TypeInterfaces* other) const; 1145 bool contains(const TypeInterfaces* other) const { 1146 return intersection_with(other)->eq(other); 1147 } 1148 bool empty() const { return _interfaces.length() == 0; } 1149 1150 ciInstanceKlass* exact_klass() const; 1151 void verify_is_loaded() const NOT_DEBUG_RETURN; 1152 1153 static int compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2); 1154 static int compare(ciInstanceKlass** k1, ciInstanceKlass** k2); 1155 1156 const Type* xmeet(const Type* t) const; 1157 1158 bool singleton(void) const; 1159 bool has_non_array_interface() const; 1160 }; 1161 1162 //------------------------------TypePtr---------------------------------------- 1163 // Class of machine Pointer Types: raw data, instances or arrays. 1164 // If the _base enum is AnyPtr, then this refers to all of the above. 1165 // Otherwise the _base will indicate which subset of pointers is affected, 1166 // and the class will be inherited from. 1167 class TypePtr : public Type { 1168 friend class TypeNarrowPtr; 1169 friend class Type; 1170 protected: 1171 static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling); 1172 1173 public: 1174 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR }; 1175 protected: 1176 TypePtr(TYPES t, PTR ptr, int offset, 1177 relocInfo::relocType reloc, 1178 const TypePtr* speculative = nullptr, 1179 int inline_depth = InlineDepthBottom) : 1180 Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset), 1181 _ptr(ptr), _reloc(reloc) {} 1182 static const PTR ptr_meet[lastPTR][lastPTR]; 1183 static const PTR ptr_dual[lastPTR]; 1184 static const char * const ptr_msg[lastPTR]; 1185 1186 enum { 1187 InlineDepthBottom = INT_MAX, 1188 InlineDepthTop = -InlineDepthBottom 1189 }; 1190 1191 // Extra type information profiling gave us. We propagate it the 1192 // same way the rest of the type info is propagated. If we want to 1193 // use it, then we have to emit a guard: this part of the type is 1194 // not something we know but something we speculate about the type. 1195 const TypePtr* _speculative; 1196 // For speculative types, we record at what inlining depth the 1197 // profiling point that provided the data is. We want to favor 1198 // profile data coming from outer scopes which are likely better for 1199 // the current compilation. 1200 int _inline_depth; 1201 1202 // utility methods to work on the speculative part of the type 1203 const TypePtr* dual_speculative() const; 1204 const TypePtr* xmeet_speculative(const TypePtr* other) const; 1205 bool eq_speculative(const TypePtr* other) const; 1206 int hash_speculative() const; 1207 const TypePtr* add_offset_speculative(intptr_t offset) const; 1208 const TypePtr* with_offset_speculative(intptr_t offset) const; 1209 1210 // utility methods to work on the inline depth of the type 1211 int dual_inline_depth() const; 1212 int meet_inline_depth(int depth) const; 1213 1214 #ifndef PRODUCT 1215 void dump_speculative(outputStream* st) const; 1216 void dump_inline_depth(outputStream* st) const; 1217 void dump_offset(outputStream* st) const; 1218 #endif 1219 1220 // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic. 1221 // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for 1222 // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what 1223 // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was 1224 // encountered so the right logic specific to klasses or oops can be executed., 1225 enum MeetResult { 1226 QUICK, 1227 UNLOADED, 1228 SUBTYPE, 1229 NOT_SUBTYPE, 1230 LCA 1231 }; 1232 template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, 1233 const T* other_type, ciKlass*& res_klass, bool& res_xk); 1234 1235 template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary, 1236 ciKlass*& res_klass, bool& res_xk); 1237 1238 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); 1239 template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other); 1240 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); 1241 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); 1242 template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other); 1243 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); 1244 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); 1245 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); 1246 public: 1247 const int _offset; // Offset into oop, with TOP & BOT 1248 const PTR _ptr; // Pointer equivalence class 1249 const relocInfo::relocType _reloc; 1250 1251 int offset() const { return _offset; } 1252 PTR ptr() const { return _ptr; } 1253 relocInfo::relocType reloc() const { return _reloc; } 1254 1255 static const TypePtr *make(TYPES t, PTR ptr, int offset, 1256 const TypePtr* speculative = nullptr, 1257 int inline_depth = InlineDepthBottom, 1258 relocInfo::relocType reloc = relocInfo::none); 1259 1260 // Return a 'ptr' version of this type 1261 virtual const TypePtr* cast_to_ptr_type(PTR ptr) const; 1262 1263 virtual intptr_t get_con() const; 1264 1265 int xadd_offset( intptr_t offset ) const; 1266 virtual const TypePtr* add_offset(intptr_t offset) const; 1267 virtual const TypePtr* with_offset(intptr_t offset) const; 1268 virtual bool eq(const Type *t) const; 1269 virtual uint hash() const; // Type specific hashing 1270 1271 virtual bool singleton(void) const; // TRUE if type is a singleton 1272 virtual bool empty(void) const; // TRUE if type is vacuous 1273 virtual const Type *xmeet( const Type *t ) const; 1274 virtual const Type *xmeet_helper( const Type *t ) const; 1275 int meet_offset( int offset ) const; 1276 int dual_offset( ) const; 1277 virtual const Type *xdual() const; // Compute dual right now. 1278 1279 // meet, dual and join over pointer equivalence sets 1280 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; } 1281 PTR dual_ptr() const { return ptr_dual[ptr()]; } 1282 1283 // This is textually confusing unless one recalls that 1284 // join(t) == dual()->meet(t->dual())->dual(). 1285 PTR join_ptr( const PTR in_ptr ) const { 1286 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ]; 1287 } 1288 1289 // Speculative type helper methods. 1290 virtual const TypePtr* speculative() const { return _speculative; } 1291 int inline_depth() const { return _inline_depth; } 1292 virtual ciKlass* speculative_type() const; 1293 virtual ciKlass* speculative_type_not_null() const; 1294 virtual bool speculative_maybe_null() const; 1295 virtual bool speculative_always_null() const; 1296 virtual const TypePtr* remove_speculative() const; 1297 virtual const Type* cleanup_speculative() const; 1298 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const; 1299 virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const; 1300 virtual const TypePtr* with_inline_depth(int depth) const; 1301 1302 virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); } 1303 1304 // Tests for relation to centerline of type lattice: 1305 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); } 1306 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); } 1307 // Convenience common pre-built types. 1308 static const TypePtr *NULL_PTR; 1309 static const TypePtr *NOTNULL; 1310 static const TypePtr *BOTTOM; 1311 #ifndef PRODUCT 1312 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1313 #endif 1314 }; 1315 1316 //------------------------------TypeRawPtr------------------------------------- 1317 // Class of raw pointers, pointers to things other than Oops. Examples 1318 // include the stack pointer, top of heap, card-marking area, handles, etc. 1319 class TypeRawPtr : public TypePtr { 1320 protected: 1321 TypeRawPtr(PTR ptr, address bits, relocInfo::relocType reloc) : TypePtr(RawPtr, ptr, 0, reloc), _bits(bits){} 1322 public: 1323 virtual bool eq( const Type *t ) const; 1324 virtual uint hash() const; // Type specific hashing 1325 1326 const address _bits; // Constant value, if applicable 1327 1328 static const TypeRawPtr* make(PTR ptr); 1329 static const TypeRawPtr* make(address bits, relocInfo::relocType reloc = relocInfo::external_word_type); 1330 1331 // Return a 'ptr' version of this type 1332 virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const; 1333 1334 virtual intptr_t get_con() const; 1335 1336 virtual const TypePtr* add_offset(intptr_t offset) const; 1337 virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;} 1338 1339 virtual const Type *xmeet( const Type *t ) const; 1340 virtual const Type *xdual() const; // Compute dual right now. 1341 // Convenience common pre-built types. 1342 static const TypeRawPtr *BOTTOM; 1343 static const TypeRawPtr *NOTNULL; 1344 #ifndef PRODUCT 1345 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1346 #endif 1347 }; 1348 1349 //------------------------------TypeOopPtr------------------------------------- 1350 // Some kind of oop (Java pointer), either instance or array. 1351 class TypeOopPtr : public TypePtr { 1352 friend class TypeAry; 1353 friend class TypePtr; 1354 friend class TypeInstPtr; 1355 friend class TypeAryPtr; 1356 protected: 1357 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id, 1358 const TypePtr* speculative, int inline_depth); 1359 public: 1360 virtual bool eq( const Type *t ) const; 1361 virtual uint hash() const; // Type specific hashing 1362 virtual bool singleton(void) const; // TRUE if type is a singleton 1363 enum { 1364 InstanceTop = -1, // undefined instance 1365 InstanceBot = 0 // any possible instance 1366 }; 1367 protected: 1368 1369 // Oop is null, unless this is a constant oop. 1370 ciObject* _const_oop; // Constant oop 1371 // If _klass is null, then so is _sig. This is an unloaded klass. 1372 ciKlass* _klass; // Klass object 1373 1374 const TypeInterfaces* _interfaces; 1375 1376 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.) 1377 bool _klass_is_exact; 1378 bool _is_ptr_to_narrowoop; 1379 bool _is_ptr_to_narrowklass; 1380 bool _is_ptr_to_boxed_value; 1381 1382 // If not InstanceTop or InstanceBot, indicates that this is 1383 // a particular instance of this type which is distinct. 1384 // This is the node index of the allocation node creating this instance. 1385 int _instance_id; 1386 1387 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling); 1388 1389 int dual_instance_id() const; 1390 int meet_instance_id(int uid) const; 1391 1392 const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const; 1393 1394 // Do not allow interface-vs.-noninterface joins to collapse to top. 1395 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1396 1397 virtual ciKlass* exact_klass_helper() const { return nullptr; } 1398 virtual ciKlass* klass() const { return _klass; } 1399 1400 #ifndef PRODUCT 1401 void dump_instance_id(outputStream* st) const; 1402 #endif // PRODUCT 1403 1404 public: 1405 1406 bool is_java_subtype_of(const TypeOopPtr* other) const { 1407 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1408 } 1409 1410 bool is_same_java_type_as(const TypePtr* other) const { 1411 return is_same_java_type_as_helper(other->is_oopptr()); 1412 } 1413 1414 virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const { 1415 ShouldNotReachHere(); return false; 1416 } 1417 1418 bool maybe_java_subtype_of(const TypeOopPtr* other) const { 1419 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1420 } 1421 virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1422 virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1423 1424 1425 // Creates a type given a klass. Correctly handles multi-dimensional arrays 1426 // Respects UseUniqueSubclasses. 1427 // If the klass is final, the resulting type will be exact. 1428 static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) { 1429 return make_from_klass_common(klass, true, false, interface_handling); 1430 } 1431 // Same as before, but will produce an exact type, even if 1432 // the klass is not final, as long as it has exactly one implementation. 1433 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) { 1434 return make_from_klass_common(klass, true, true, interface_handling); 1435 } 1436 // Same as before, but does not respects UseUniqueSubclasses. 1437 // Use this only for creating array element types. 1438 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) { 1439 return make_from_klass_common(klass, false, false, interface_handling); 1440 } 1441 // Creates a singleton type given an object. 1442 // If the object cannot be rendered as a constant, 1443 // may return a non-singleton type. 1444 // If require_constant, produce a null if a singleton is not possible. 1445 static const TypeOopPtr* make_from_constant(ciObject* o, 1446 bool require_constant = false); 1447 1448 // Make a generic (unclassed) pointer to an oop. 1449 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, 1450 const TypePtr* speculative = nullptr, 1451 int inline_depth = InlineDepthBottom); 1452 1453 ciObject* const_oop() const { return _const_oop; } 1454 // Exact klass, possibly an interface or an array of interface 1455 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; } 1456 ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); } 1457 1458 virtual bool is_loaded() const { return klass()->is_loaded(); } 1459 virtual bool klass_is_exact() const { return _klass_is_exact; } 1460 1461 // Returns true if this pointer points at memory which contains a 1462 // compressed oop references. 1463 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; } 1464 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; } 1465 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; } 1466 bool is_known_instance() const { return _instance_id > 0; } 1467 int instance_id() const { return _instance_id; } 1468 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; } 1469 1470 virtual intptr_t get_con() const; 1471 1472 virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const; 1473 1474 virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const; 1475 1476 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 1477 1478 // corresponding pointer to klass, for a given instance 1479 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const; 1480 1481 virtual const TypeOopPtr* with_offset(intptr_t offset) const; 1482 virtual const TypePtr* add_offset(intptr_t offset) const; 1483 1484 // Speculative type helper methods. 1485 virtual const TypeOopPtr* remove_speculative() const; 1486 virtual const Type* cleanup_speculative() const; 1487 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const; 1488 virtual const TypePtr* with_inline_depth(int depth) const; 1489 1490 virtual const TypePtr* with_instance_id(int instance_id) const; 1491 1492 virtual const Type *xdual() const; // Compute dual right now. 1493 // the core of the computation of the meet for TypeOopPtr and for its subclasses 1494 virtual const Type *xmeet_helper(const Type *t) const; 1495 1496 // Convenience common pre-built type. 1497 static const TypeOopPtr *BOTTOM; 1498 #ifndef PRODUCT 1499 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1500 #endif 1501 private: 1502 virtual bool is_meet_subtype_of(const TypePtr* other) const { 1503 return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact()); 1504 } 1505 1506 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const { 1507 ShouldNotReachHere(); return false; 1508 } 1509 1510 virtual const TypeInterfaces* interfaces() const { 1511 return _interfaces; 1512 }; 1513 1514 const TypeOopPtr* is_reference_type(const Type* other) const { 1515 return other->isa_oopptr(); 1516 } 1517 1518 const TypeAryPtr* is_array_type(const TypeOopPtr* other) const { 1519 return other->isa_aryptr(); 1520 } 1521 1522 const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const { 1523 return other->isa_instptr(); 1524 } 1525 }; 1526 1527 //------------------------------TypeInstPtr------------------------------------ 1528 // Class of Java object pointers, pointing either to non-array Java instances 1529 // or to a Klass* (including array klasses). 1530 class TypeInstPtr : public TypeOopPtr { 1531 TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id, 1532 const TypePtr* speculative, int inline_depth); 1533 virtual bool eq( const Type *t ) const; 1534 virtual uint hash() const; // Type specific hashing 1535 1536 ciKlass* exact_klass_helper() const; 1537 1538 public: 1539 1540 // Instance klass, ignoring any interface 1541 ciInstanceKlass* instance_klass() const { 1542 assert(!(klass()->is_loaded() && klass()->is_interface()), ""); 1543 return klass()->as_instance_klass(); 1544 } 1545 1546 bool is_same_java_type_as_helper(const TypeOopPtr* other) const; 1547 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1548 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1549 1550 // Make a pointer to a constant oop. 1551 static const TypeInstPtr *make(ciObject* o) { 1552 ciKlass* k = o->klass(); 1553 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1554 return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot); 1555 } 1556 // Make a pointer to a constant oop with offset. 1557 static const TypeInstPtr *make(ciObject* o, int offset) { 1558 ciKlass* k = o->klass(); 1559 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1560 return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot); 1561 } 1562 1563 // Make a pointer to some value of type klass. 1564 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) { 1565 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling); 1566 return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot); 1567 } 1568 1569 // Make a pointer to some non-polymorphic value of exactly type klass. 1570 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) { 1571 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces); 1572 return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot); 1573 } 1574 1575 // Make a pointer to some value of type klass with offset. 1576 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) { 1577 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces); 1578 return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot); 1579 } 1580 1581 static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, 1582 int instance_id = InstanceBot, 1583 const TypePtr* speculative = nullptr, 1584 int inline_depth = InlineDepthBottom); 1585 1586 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) { 1587 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1588 return make(ptr, k, interfaces, xk, o, offset, instance_id); 1589 } 1590 1591 // If this is a java.lang.Class constant, return the type for it or null. 1592 // Pass to Type::get_const_type to turn it to a type, which will usually 1593 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc. 1594 ciType* java_mirror_type() const; 1595 1596 virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const; 1597 1598 virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const; 1599 1600 virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const; 1601 1602 virtual const TypePtr* add_offset(intptr_t offset) const; 1603 virtual const TypeInstPtr* with_offset(intptr_t offset) const; 1604 1605 // Speculative type helper methods. 1606 virtual const TypeInstPtr* remove_speculative() const; 1607 const TypeInstPtr* with_speculative(const TypePtr* speculative) const; 1608 virtual const TypePtr* with_inline_depth(int depth) const; 1609 virtual const TypePtr* with_instance_id(int instance_id) const; 1610 1611 // the core of the computation of the meet of 2 types 1612 virtual const Type *xmeet_helper(const Type *t) const; 1613 virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const; 1614 virtual const Type *xdual() const; // Compute dual right now. 1615 1616 const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const; 1617 1618 // Convenience common pre-built types. 1619 static const TypeInstPtr *NOTNULL; 1620 static const TypeInstPtr *BOTTOM; 1621 static const TypeInstPtr *MIRROR; 1622 static const TypeInstPtr *MARK; 1623 static const TypeInstPtr *KLASS; 1624 #ifndef PRODUCT 1625 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1626 #endif 1627 1628 private: 1629 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const; 1630 1631 virtual bool is_meet_same_type_as(const TypePtr* other) const { 1632 return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces); 1633 } 1634 1635 }; 1636 1637 //------------------------------TypeAryPtr------------------------------------- 1638 // Class of Java array pointers 1639 class TypeAryPtr : public TypeOopPtr { 1640 friend class Type; 1641 friend class TypePtr; 1642 friend class TypeInterfaces; 1643 1644 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, 1645 int offset, int instance_id, bool is_autobox_cache, 1646 const TypePtr* speculative, int inline_depth) 1647 : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth), 1648 _ary(ary), 1649 _is_autobox_cache(is_autobox_cache) 1650 { 1651 int dummy; 1652 bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM); 1653 1654 if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) && 1655 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() && 1656 _offset != arrayOopDesc::klass_offset_in_bytes()) { 1657 _is_ptr_to_narrowoop = true; 1658 } 1659 1660 } 1661 virtual bool eq( const Type *t ) const; 1662 virtual uint hash() const; // Type specific hashing 1663 const TypeAry *_ary; // Array we point into 1664 const bool _is_autobox_cache; 1665 1666 ciKlass* compute_klass() const; 1667 1668 // A pointer to delay allocation to Type::Initialize_shared() 1669 1670 static const TypeInterfaces* _array_interfaces; 1671 ciKlass* exact_klass_helper() const; 1672 // Only guaranteed non null for array of basic types 1673 ciKlass* klass() const; 1674 1675 public: 1676 1677 bool is_same_java_type_as_helper(const TypeOopPtr* other) const; 1678 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1679 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1680 1681 // returns base element type, an instance klass (and not interface) for object arrays 1682 const Type* base_element_type(int& dims) const; 1683 1684 // Accessors 1685 bool is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); } 1686 1687 const TypeAry* ary() const { return _ary; } 1688 const Type* elem() const { return _ary->_elem; } 1689 const TypeInt* size() const { return _ary->_size; } 1690 bool is_stable() const { return _ary->_stable; } 1691 1692 bool is_autobox_cache() const { return _is_autobox_cache; } 1693 1694 static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, 1695 int instance_id = InstanceBot, 1696 const TypePtr* speculative = nullptr, 1697 int inline_depth = InlineDepthBottom); 1698 // Constant pointer to array 1699 static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, 1700 int instance_id = InstanceBot, 1701 const TypePtr* speculative = nullptr, 1702 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false); 1703 1704 // Return a 'ptr' version of this type 1705 virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const; 1706 1707 virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const; 1708 1709 virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const; 1710 1711 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const; 1712 virtual const TypeInt* narrow_size_type(const TypeInt* size) const; 1713 1714 virtual bool empty(void) const; // TRUE if type is vacuous 1715 virtual const TypePtr *add_offset( intptr_t offset ) const; 1716 virtual const TypeAryPtr *with_offset( intptr_t offset ) const; 1717 const TypeAryPtr* with_ary(const TypeAry* ary) const; 1718 1719 // Speculative type helper methods. 1720 virtual const TypeAryPtr* remove_speculative() const; 1721 virtual const TypePtr* with_inline_depth(int depth) const; 1722 virtual const TypePtr* with_instance_id(int instance_id) const; 1723 1724 // the core of the computation of the meet of 2 types 1725 virtual const Type *xmeet_helper(const Type *t) const; 1726 virtual const Type *xdual() const; // Compute dual right now. 1727 1728 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const; 1729 int stable_dimension() const; 1730 1731 const TypeAryPtr* cast_to_autobox_cache() const; 1732 1733 static jint max_array_length(BasicType etype) ; 1734 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const; 1735 1736 // Convenience common pre-built types. 1737 static const TypeAryPtr* BOTTOM; 1738 static const TypeAryPtr* RANGE; 1739 static const TypeAryPtr* OOPS; 1740 static const TypeAryPtr* NARROWOOPS; 1741 static const TypeAryPtr* BYTES; 1742 static const TypeAryPtr* SHORTS; 1743 static const TypeAryPtr* CHARS; 1744 static const TypeAryPtr* INTS; 1745 static const TypeAryPtr* LONGS; 1746 static const TypeAryPtr* FLOATS; 1747 static const TypeAryPtr* DOUBLES; 1748 // selects one of the above: 1749 static const TypeAryPtr *get_array_body_type(BasicType elem) { 1750 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type"); 1751 return _array_body_type[elem]; 1752 } 1753 static const TypeAryPtr *_array_body_type[T_CONFLICT+1]; 1754 // sharpen the type of an int which is used as an array size 1755 #ifndef PRODUCT 1756 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1757 #endif 1758 private: 1759 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const; 1760 }; 1761 1762 //------------------------------TypeMetadataPtr------------------------------------- 1763 // Some kind of metadata, either Method*, MethodData* or CPCacheOop 1764 class TypeMetadataPtr : public TypePtr { 1765 protected: 1766 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset); 1767 // Do not allow interface-vs.-noninterface joins to collapse to top. 1768 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1769 public: 1770 virtual bool eq( const Type *t ) const; 1771 virtual uint hash() const; // Type specific hashing 1772 virtual bool singleton(void) const; // TRUE if type is a singleton 1773 1774 private: 1775 ciMetadata* _metadata; 1776 1777 public: 1778 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset); 1779 1780 static const TypeMetadataPtr* make(ciMethod* m); 1781 static const TypeMetadataPtr* make(ciMethodData* m); 1782 1783 ciMetadata* metadata() const { return _metadata; } 1784 1785 virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const; 1786 1787 virtual const TypePtr *add_offset( intptr_t offset ) const; 1788 1789 virtual const Type *xmeet( const Type *t ) const; 1790 virtual const Type *xdual() const; // Compute dual right now. 1791 1792 virtual intptr_t get_con() const; 1793 1794 // Convenience common pre-built types. 1795 static const TypeMetadataPtr *BOTTOM; 1796 1797 #ifndef PRODUCT 1798 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1799 #endif 1800 }; 1801 1802 //------------------------------TypeKlassPtr----------------------------------- 1803 // Class of Java Klass pointers 1804 class TypeKlassPtr : public TypePtr { 1805 friend class TypeInstKlassPtr; 1806 friend class TypeAryKlassPtr; 1807 friend class TypePtr; 1808 protected: 1809 TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset); 1810 1811 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1812 1813 public: 1814 virtual bool eq( const Type *t ) const; 1815 virtual uint hash() const; 1816 virtual bool singleton(void) const; // TRUE if type is a singleton 1817 1818 protected: 1819 1820 ciKlass* _klass; 1821 const TypeInterfaces* _interfaces; 1822 const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const; 1823 virtual bool must_be_exact() const { ShouldNotReachHere(); return false; } 1824 virtual ciKlass* exact_klass_helper() const; 1825 virtual ciKlass* klass() const { return _klass; } 1826 1827 public: 1828 1829 bool is_java_subtype_of(const TypeKlassPtr* other) const { 1830 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1831 } 1832 bool is_same_java_type_as(const TypePtr* other) const { 1833 return is_same_java_type_as_helper(other->is_klassptr()); 1834 } 1835 1836 bool maybe_java_subtype_of(const TypeKlassPtr* other) const { 1837 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1838 } 1839 virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; } 1840 virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1841 virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1842 1843 // Exact klass, possibly an interface or an array of interface 1844 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; } 1845 virtual bool klass_is_exact() const { return _ptr == Constant; } 1846 1847 static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces); 1848 static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces); 1849 1850 virtual bool is_loaded() const { return _klass->is_loaded(); } 1851 1852 virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; } 1853 1854 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; } 1855 1856 // corresponding pointer to instance, for a given class 1857 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; } 1858 1859 virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; } 1860 virtual const Type *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; } 1861 virtual const Type *xdual() const { ShouldNotReachHere(); return nullptr; } 1862 1863 virtual intptr_t get_con() const; 1864 1865 virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; } 1866 1867 virtual const TypeKlassPtr* try_improve() const { return this; } 1868 1869 private: 1870 virtual bool is_meet_subtype_of(const TypePtr* other) const { 1871 return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact()); 1872 } 1873 1874 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const { 1875 ShouldNotReachHere(); return false; 1876 } 1877 1878 virtual const TypeInterfaces* interfaces() const { 1879 return _interfaces; 1880 }; 1881 1882 const TypeKlassPtr* is_reference_type(const Type* other) const { 1883 return other->isa_klassptr(); 1884 } 1885 1886 const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const { 1887 return other->isa_aryklassptr(); 1888 } 1889 1890 const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const { 1891 return other->isa_instklassptr(); 1892 } 1893 }; 1894 1895 // Instance klass pointer, mirrors TypeInstPtr 1896 class TypeInstKlassPtr : public TypeKlassPtr { 1897 1898 TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset) 1899 : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) { 1900 assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), ""); 1901 } 1902 1903 virtual bool must_be_exact() const; 1904 1905 public: 1906 // Instance klass ignoring any interface 1907 ciInstanceKlass* instance_klass() const { 1908 assert(!klass()->is_interface(), ""); 1909 return klass()->as_instance_klass(); 1910 } 1911 1912 bool might_be_an_array() const; 1913 1914 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const; 1915 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1916 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1917 1918 static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) { 1919 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling); 1920 return make(TypePtr::Constant, k, interfaces, 0); 1921 } 1922 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset); 1923 1924 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) { 1925 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1926 return make(ptr, k, interfaces, offset); 1927 } 1928 1929 virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const; 1930 1931 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const; 1932 1933 // corresponding pointer to instance, for a given class 1934 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const; 1935 virtual uint hash() const; 1936 virtual bool eq(const Type *t) const; 1937 1938 virtual const TypePtr *add_offset( intptr_t offset ) const; 1939 virtual const Type *xmeet( const Type *t ) const; 1940 virtual const Type *xdual() const; 1941 virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const; 1942 1943 virtual const TypeKlassPtr* try_improve() const; 1944 1945 // Convenience common pre-built types. 1946 static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below 1947 static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same 1948 1949 #ifndef PRODUCT 1950 virtual void dump2(Dict& d, uint depth, outputStream* st) const; 1951 #endif // PRODUCT 1952 1953 private: 1954 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const; 1955 }; 1956 1957 // Array klass pointer, mirrors TypeAryPtr 1958 class TypeAryKlassPtr : public TypeKlassPtr { 1959 friend class TypeInstKlassPtr; 1960 friend class Type; 1961 friend class TypePtr; 1962 1963 const Type *_elem; 1964 1965 static const TypeInterfaces* _array_interfaces; 1966 TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset) 1967 : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) { 1968 assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), ""); 1969 } 1970 1971 virtual ciKlass* exact_klass_helper() const; 1972 // Only guaranteed non null for array of basic types 1973 virtual ciKlass* klass() const; 1974 1975 virtual bool must_be_exact() const; 1976 1977 public: 1978 1979 // returns base element type, an instance klass (and not interface) for object arrays 1980 const Type* base_element_type(int& dims) const; 1981 1982 static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling); 1983 1984 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const; 1985 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1986 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1987 1988 bool is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); } 1989 1990 static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset); 1991 static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling); 1992 1993 const Type *elem() const { return _elem; } 1994 1995 virtual bool eq(const Type *t) const; 1996 virtual uint hash() const; // Type specific hashing 1997 1998 virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const; 1999 2000 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const; 2001 2002 // corresponding pointer to instance, for a given class 2003 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const; 2004 2005 virtual const TypePtr *add_offset( intptr_t offset ) const; 2006 virtual const Type *xmeet( const Type *t ) const; 2007 virtual const Type *xdual() const; // Compute dual right now. 2008 2009 virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const; 2010 2011 virtual bool empty(void) const { 2012 return TypeKlassPtr::empty() || _elem->empty(); 2013 } 2014 2015 #ifndef PRODUCT 2016 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 2017 #endif 2018 private: 2019 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const; 2020 }; 2021 2022 class TypeNarrowPtr : public Type { 2023 protected: 2024 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR 2025 2026 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t), 2027 _ptrtype(ptrtype) { 2028 assert(ptrtype->offset() == 0 || 2029 ptrtype->offset() == OffsetBot || 2030 ptrtype->offset() == OffsetTop, "no real offsets"); 2031 } 2032 2033 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0; 2034 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0; 2035 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0; 2036 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0; 2037 // Do not allow interface-vs.-noninterface joins to collapse to top. 2038 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 2039 public: 2040 virtual bool eq( const Type *t ) const; 2041 virtual uint hash() const; // Type specific hashing 2042 virtual bool singleton(void) const; // TRUE if type is a singleton 2043 2044 virtual const Type *xmeet( const Type *t ) const; 2045 virtual const Type *xdual() const; // Compute dual right now. 2046 2047 virtual intptr_t get_con() const; 2048 2049 virtual bool empty(void) const; // TRUE if type is vacuous 2050 2051 // returns the equivalent ptr type for this compressed pointer 2052 const TypePtr *get_ptrtype() const { 2053 return _ptrtype; 2054 } 2055 2056 bool is_known_instance() const { 2057 return _ptrtype->is_known_instance(); 2058 } 2059 2060 #ifndef PRODUCT 2061 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 2062 #endif 2063 }; 2064 2065 //------------------------------TypeNarrowOop---------------------------------- 2066 // A compressed reference to some kind of Oop. This type wraps around 2067 // a preexisting TypeOopPtr and forwards most of it's operations to 2068 // the underlying type. It's only real purpose is to track the 2069 // oopness of the compressed oop value when we expose the conversion 2070 // between the normal and the compressed form. 2071 class TypeNarrowOop : public TypeNarrowPtr { 2072 protected: 2073 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) { 2074 } 2075 2076 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const { 2077 return t->isa_narrowoop(); 2078 } 2079 2080 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const { 2081 return t->is_narrowoop(); 2082 } 2083 2084 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const { 2085 return new TypeNarrowOop(t); 2086 } 2087 2088 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const { 2089 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons()); 2090 } 2091 2092 public: 2093 2094 static const TypeNarrowOop *make( const TypePtr* type); 2095 2096 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) { 2097 return make(TypeOopPtr::make_from_constant(con, require_constant)); 2098 } 2099 2100 static const TypeNarrowOop *BOTTOM; 2101 static const TypeNarrowOop *NULL_PTR; 2102 2103 virtual const TypeNarrowOop* remove_speculative() const; 2104 virtual const Type* cleanup_speculative() const; 2105 2106 #ifndef PRODUCT 2107 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 2108 #endif 2109 }; 2110 2111 //------------------------------TypeNarrowKlass---------------------------------- 2112 // A compressed reference to klass pointer. This type wraps around a 2113 // preexisting TypeKlassPtr and forwards most of it's operations to 2114 // the underlying type. 2115 class TypeNarrowKlass : public TypeNarrowPtr { 2116 protected: 2117 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) { 2118 } 2119 2120 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const { 2121 return t->isa_narrowklass(); 2122 } 2123 2124 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const { 2125 return t->is_narrowklass(); 2126 } 2127 2128 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const { 2129 return new TypeNarrowKlass(t); 2130 } 2131 2132 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const { 2133 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons()); 2134 } 2135 2136 public: 2137 static const TypeNarrowKlass *make( const TypePtr* type); 2138 2139 // static const TypeNarrowKlass *BOTTOM; 2140 static const TypeNarrowKlass *NULL_PTR; 2141 2142 #ifndef PRODUCT 2143 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 2144 #endif 2145 }; 2146 2147 //------------------------------TypeFunc--------------------------------------- 2148 // Class of Array Types 2149 class TypeFunc : public Type { 2150 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {} 2151 virtual bool eq( const Type *t ) const; 2152 virtual uint hash() const; // Type specific hashing 2153 virtual bool singleton(void) const; // TRUE if type is a singleton 2154 virtual bool empty(void) const; // TRUE if type is vacuous 2155 2156 const TypeTuple* const _domain; // Domain of inputs 2157 const TypeTuple* const _range; // Range of results 2158 2159 public: 2160 // Constants are shared among ADLC and VM 2161 enum { Control = AdlcVMDeps::Control, 2162 I_O = AdlcVMDeps::I_O, 2163 Memory = AdlcVMDeps::Memory, 2164 FramePtr = AdlcVMDeps::FramePtr, 2165 ReturnAdr = AdlcVMDeps::ReturnAdr, 2166 Parms = AdlcVMDeps::Parms 2167 }; 2168 2169 2170 // Accessors: 2171 const TypeTuple* domain() const { return _domain; } 2172 const TypeTuple* range() const { return _range; } 2173 2174 static const TypeFunc *make(ciMethod* method); 2175 static const TypeFunc *make(ciSignature signature, const Type* extra); 2176 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range); 2177 2178 virtual const Type *xmeet( const Type *t ) const; 2179 virtual const Type *xdual() const; // Compute dual right now. 2180 2181 BasicType return_type() const; 2182 2183 #ifndef PRODUCT 2184 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 2185 #endif 2186 // Convenience common pre-built types. 2187 }; 2188 2189 //------------------------------accessors-------------------------------------- 2190 inline bool Type::is_ptr_to_narrowoop() const { 2191 #ifdef _LP64 2192 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv()); 2193 #else 2194 return false; 2195 #endif 2196 } 2197 2198 inline bool Type::is_ptr_to_narrowklass() const { 2199 #ifdef _LP64 2200 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv()); 2201 #else 2202 return false; 2203 #endif 2204 } 2205 2206 inline float Type::getf() const { 2207 assert( _base == FloatCon, "Not a FloatCon" ); 2208 return ((TypeF*)this)->_f; 2209 } 2210 2211 inline short Type::geth() const { 2212 assert(_base == HalfFloatCon, "Not a HalfFloatCon"); 2213 return ((TypeH*)this)->_f; 2214 } 2215 2216 inline double Type::getd() const { 2217 assert( _base == DoubleCon, "Not a DoubleCon" ); 2218 return ((TypeD*)this)->_d; 2219 } 2220 2221 inline const TypeInteger *Type::is_integer(BasicType bt) const { 2222 assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int"); 2223 return (TypeInteger*)this; 2224 } 2225 2226 inline const TypeInteger *Type::isa_integer(BasicType bt) const { 2227 return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : nullptr); 2228 } 2229 2230 inline const TypeInt *Type::is_int() const { 2231 assert( _base == Int, "Not an Int" ); 2232 return (TypeInt*)this; 2233 } 2234 2235 inline const TypeInt *Type::isa_int() const { 2236 return ( _base == Int ? (TypeInt*)this : nullptr); 2237 } 2238 2239 inline const TypeLong *Type::is_long() const { 2240 assert( _base == Long, "Not a Long" ); 2241 return (TypeLong*)this; 2242 } 2243 2244 inline const TypeLong *Type::isa_long() const { 2245 return ( _base == Long ? (TypeLong*)this : nullptr); 2246 } 2247 2248 inline const TypeH* Type::isa_half_float() const { 2249 return ((_base == HalfFloatTop || 2250 _base == HalfFloatCon || 2251 _base == HalfFloatBot) ? (TypeH*)this : nullptr); 2252 } 2253 2254 inline const TypeH* Type::is_half_float_constant() const { 2255 assert( _base == HalfFloatCon, "Not a HalfFloat" ); 2256 return (TypeH*)this; 2257 } 2258 2259 inline const TypeH* Type::isa_half_float_constant() const { 2260 return (_base == HalfFloatCon ? (TypeH*)this : nullptr); 2261 } 2262 2263 inline const TypeF *Type::isa_float() const { 2264 return ((_base == FloatTop || 2265 _base == FloatCon || 2266 _base == FloatBot) ? (TypeF*)this : nullptr); 2267 } 2268 2269 inline const TypeF *Type::is_float_constant() const { 2270 assert( _base == FloatCon, "Not a Float" ); 2271 return (TypeF*)this; 2272 } 2273 2274 inline const TypeF *Type::isa_float_constant() const { 2275 return ( _base == FloatCon ? (TypeF*)this : nullptr); 2276 } 2277 2278 inline const TypeD *Type::isa_double() const { 2279 return ((_base == DoubleTop || 2280 _base == DoubleCon || 2281 _base == DoubleBot) ? (TypeD*)this : nullptr); 2282 } 2283 2284 inline const TypeD *Type::is_double_constant() const { 2285 assert( _base == DoubleCon, "Not a Double" ); 2286 return (TypeD*)this; 2287 } 2288 2289 inline const TypeD *Type::isa_double_constant() const { 2290 return ( _base == DoubleCon ? (TypeD*)this : nullptr); 2291 } 2292 2293 inline const TypeTuple *Type::is_tuple() const { 2294 assert( _base == Tuple, "Not a Tuple" ); 2295 return (TypeTuple*)this; 2296 } 2297 2298 inline const TypeAry *Type::is_ary() const { 2299 assert( _base == Array , "Not an Array" ); 2300 return (TypeAry*)this; 2301 } 2302 2303 inline const TypeAry *Type::isa_ary() const { 2304 return ((_base == Array) ? (TypeAry*)this : nullptr); 2305 } 2306 2307 inline const TypePVectMask *Type::is_pvectmask() const { 2308 assert( _base == VectorMask, "Not a Vector Mask" ); 2309 return (TypePVectMask*)this; 2310 } 2311 2312 inline const TypePVectMask *Type::isa_pvectmask() const { 2313 return (_base == VectorMask) ? (TypePVectMask*)this : nullptr; 2314 } 2315 2316 inline const TypeVect *Type::is_vect() const { 2317 assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" ); 2318 return (TypeVect*)this; 2319 } 2320 2321 inline const TypeVect *Type::isa_vect() const { 2322 return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : nullptr; 2323 } 2324 2325 inline const TypePtr *Type::is_ptr() const { 2326 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between. 2327 assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer"); 2328 return (TypePtr*)this; 2329 } 2330 2331 inline const TypePtr *Type::isa_ptr() const { 2332 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between. 2333 return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : nullptr; 2334 } 2335 2336 inline const TypeOopPtr *Type::is_oopptr() const { 2337 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2338 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ; 2339 return (TypeOopPtr*)this; 2340 } 2341 2342 inline const TypeOopPtr *Type::isa_oopptr() const { 2343 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2344 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : nullptr; 2345 } 2346 2347 inline const TypeRawPtr *Type::isa_rawptr() const { 2348 return (_base == RawPtr) ? (TypeRawPtr*)this : nullptr; 2349 } 2350 2351 inline const TypeRawPtr *Type::is_rawptr() const { 2352 assert( _base == RawPtr, "Not a raw pointer" ); 2353 return (TypeRawPtr*)this; 2354 } 2355 2356 inline const TypeInstPtr *Type::isa_instptr() const { 2357 return (_base == InstPtr) ? (TypeInstPtr*)this : nullptr; 2358 } 2359 2360 inline const TypeInstPtr *Type::is_instptr() const { 2361 assert( _base == InstPtr, "Not an object pointer" ); 2362 return (TypeInstPtr*)this; 2363 } 2364 2365 inline const TypeAryPtr *Type::isa_aryptr() const { 2366 return (_base == AryPtr) ? (TypeAryPtr*)this : nullptr; 2367 } 2368 2369 inline const TypeAryPtr *Type::is_aryptr() const { 2370 assert( _base == AryPtr, "Not an array pointer" ); 2371 return (TypeAryPtr*)this; 2372 } 2373 2374 inline const TypeNarrowOop *Type::is_narrowoop() const { 2375 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2376 assert(_base == NarrowOop, "Not a narrow oop" ) ; 2377 return (TypeNarrowOop*)this; 2378 } 2379 2380 inline const TypeNarrowOop *Type::isa_narrowoop() const { 2381 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2382 return (_base == NarrowOop) ? (TypeNarrowOop*)this : nullptr; 2383 } 2384 2385 inline const TypeNarrowKlass *Type::is_narrowklass() const { 2386 assert(_base == NarrowKlass, "Not a narrow oop" ) ; 2387 return (TypeNarrowKlass*)this; 2388 } 2389 2390 inline const TypeNarrowKlass *Type::isa_narrowklass() const { 2391 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : nullptr; 2392 } 2393 2394 inline const TypeMetadataPtr *Type::is_metadataptr() const { 2395 // MetadataPtr is the first and CPCachePtr the last 2396 assert(_base == MetadataPtr, "Not a metadata pointer" ) ; 2397 return (TypeMetadataPtr*)this; 2398 } 2399 2400 inline const TypeMetadataPtr *Type::isa_metadataptr() const { 2401 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : nullptr; 2402 } 2403 2404 inline const TypeKlassPtr *Type::isa_klassptr() const { 2405 return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : nullptr; 2406 } 2407 2408 inline const TypeKlassPtr *Type::is_klassptr() const { 2409 assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer"); 2410 return (TypeKlassPtr*)this; 2411 } 2412 2413 inline const TypeInstKlassPtr *Type::isa_instklassptr() const { 2414 return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : nullptr; 2415 } 2416 2417 inline const TypeInstKlassPtr *Type::is_instklassptr() const { 2418 assert(_base == InstKlassPtr, "Not a klass pointer"); 2419 return (TypeInstKlassPtr*)this; 2420 } 2421 2422 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const { 2423 return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : nullptr; 2424 } 2425 2426 inline const TypeAryKlassPtr *Type::is_aryklassptr() const { 2427 assert(_base == AryKlassPtr, "Not a klass pointer"); 2428 return (TypeAryKlassPtr*)this; 2429 } 2430 2431 inline const TypePtr* Type::make_ptr() const { 2432 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() : 2433 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() : 2434 isa_ptr()); 2435 } 2436 2437 inline const TypeOopPtr* Type::make_oopptr() const { 2438 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr(); 2439 } 2440 2441 inline const TypeNarrowOop* Type::make_narrowoop() const { 2442 return (_base == NarrowOop) ? is_narrowoop() : 2443 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr); 2444 } 2445 2446 inline const TypeNarrowKlass* Type::make_narrowklass() const { 2447 return (_base == NarrowKlass) ? is_narrowklass() : 2448 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr); 2449 } 2450 2451 inline bool Type::is_floatingpoint() const { 2452 if( (_base == HalfFloatCon) || (_base == HalfFloatBot) || 2453 (_base == FloatCon) || (_base == FloatBot) || 2454 (_base == DoubleCon) || (_base == DoubleBot) ) 2455 return true; 2456 return false; 2457 } 2458 2459 template <> 2460 inline const TypeInt* Type::cast<TypeInt>() const { 2461 return is_int(); 2462 } 2463 2464 template <> 2465 inline const TypeLong* Type::cast<TypeLong>() const { 2466 return is_long(); 2467 } 2468 2469 template <> 2470 inline const TypeInt* Type::try_cast<TypeInt>() const { 2471 return isa_int(); 2472 } 2473 2474 template <> 2475 inline const TypeLong* Type::try_cast<TypeLong>() const { 2476 return isa_long(); 2477 } 2478 2479 // =============================================================== 2480 // Things that need to be 64-bits in the 64-bit build but 2481 // 32-bits in the 32-bit build. Done this way to get full 2482 // optimization AND strong typing. 2483 #ifdef _LP64 2484 2485 // For type queries and asserts 2486 #define is_intptr_t is_long 2487 #define isa_intptr_t isa_long 2488 #define find_intptr_t_type find_long_type 2489 #define find_intptr_t_con find_long_con 2490 #define TypeX TypeLong 2491 #define Type_X Type::Long 2492 #define TypeX_X TypeLong::LONG 2493 #define TypeX_ZERO TypeLong::ZERO 2494 // For 'ideal_reg' machine registers 2495 #define Op_RegX Op_RegL 2496 // For phase->intcon variants 2497 #define MakeConX longcon 2498 #define ConXNode ConLNode 2499 // For array index arithmetic 2500 #define MulXNode MulLNode 2501 #define AndXNode AndLNode 2502 #define OrXNode OrLNode 2503 #define CmpXNode CmpLNode 2504 #define SubXNode SubLNode 2505 #define LShiftXNode LShiftLNode 2506 // For object size computation: 2507 #define AddXNode AddLNode 2508 #define RShiftXNode RShiftLNode 2509 // For card marks and hashcodes 2510 #define URShiftXNode URShiftLNode 2511 // For shenandoahSupport 2512 #define LoadXNode LoadLNode 2513 #define StoreXNode StoreLNode 2514 // Opcodes 2515 #define Op_LShiftX Op_LShiftL 2516 #define Op_AndX Op_AndL 2517 #define Op_AddX Op_AddL 2518 #define Op_SubX Op_SubL 2519 #define Op_XorX Op_XorL 2520 #define Op_URShiftX Op_URShiftL 2521 #define Op_LoadX Op_LoadL 2522 // conversions 2523 #define ConvI2X(x) ConvI2L(x) 2524 #define ConvL2X(x) (x) 2525 #define ConvX2I(x) ConvL2I(x) 2526 #define ConvX2L(x) (x) 2527 #define ConvX2UL(x) (x) 2528 2529 #else 2530 2531 // For type queries and asserts 2532 #define is_intptr_t is_int 2533 #define isa_intptr_t isa_int 2534 #define find_intptr_t_type find_int_type 2535 #define find_intptr_t_con find_int_con 2536 #define TypeX TypeInt 2537 #define Type_X Type::Int 2538 #define TypeX_X TypeInt::INT 2539 #define TypeX_ZERO TypeInt::ZERO 2540 // For 'ideal_reg' machine registers 2541 #define Op_RegX Op_RegI 2542 // For phase->intcon variants 2543 #define MakeConX intcon 2544 #define ConXNode ConINode 2545 // For array index arithmetic 2546 #define MulXNode MulINode 2547 #define AndXNode AndINode 2548 #define OrXNode OrINode 2549 #define CmpXNode CmpINode 2550 #define SubXNode SubINode 2551 #define LShiftXNode LShiftINode 2552 // For object size computation: 2553 #define AddXNode AddINode 2554 #define RShiftXNode RShiftINode 2555 // For card marks and hashcodes 2556 #define URShiftXNode URShiftINode 2557 // For shenandoahSupport 2558 #define LoadXNode LoadINode 2559 #define StoreXNode StoreINode 2560 // Opcodes 2561 #define Op_LShiftX Op_LShiftI 2562 #define Op_AndX Op_AndI 2563 #define Op_AddX Op_AddI 2564 #define Op_SubX Op_SubI 2565 #define Op_XorX Op_XorI 2566 #define Op_URShiftX Op_URShiftI 2567 #define Op_LoadX Op_LoadI 2568 // conversions 2569 #define ConvI2X(x) (x) 2570 #define ConvL2X(x) ConvL2I(x) 2571 #define ConvX2I(x) (x) 2572 #define ConvX2L(x) ConvI2L(x) 2573 #define ConvX2UL(x) ConvI2UL(x) 2574 2575 #endif 2576 2577 #endif // SHARE_OPTO_TYPE_HPP --- EOF ---