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