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