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