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