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