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