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 };
 983 
 984 //------------------------------TypePtr----------------------------------------
 985 // Class of machine Pointer Types: raw data, instances or arrays.
 986 // If the _base enum is AnyPtr, then this refers to all of the above.
 987 // Otherwise the _base will indicate which subset of pointers is affected,
 988 // and the class will be inherited from.
 989 class TypePtr : public Type {
 990   friend class TypeNarrowPtr;
 991   friend class Type;
 992 protected:
 993   static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
 994 
 995 public:
 996   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
 997 protected:
 998   TypePtr(TYPES t, PTR ptr, Offset offset,
 999           const TypePtr* speculative = nullptr,
1000           int inline_depth = InlineDepthBottom) :
1001     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1002     _ptr(ptr) {}
1003   static const PTR ptr_meet[lastPTR][lastPTR];
1004   static const PTR ptr_dual[lastPTR];
1005   static const char * const ptr_msg[lastPTR];
1006 
1007   enum {
1008     InlineDepthBottom = INT_MAX,
1009     InlineDepthTop = -InlineDepthBottom
1010   };
1011 
1012   // Extra type information profiling gave us. We propagate it the
1013   // same way the rest of the type info is propagated. If we want to
1014   // use it, then we have to emit a guard: this part of the type is
1015   // not something we know but something we speculate about the type.
1016   const TypePtr*   _speculative;
1017   // For speculative types, we record at what inlining depth the
1018   // profiling point that provided the data is. We want to favor
1019   // profile data coming from outer scopes which are likely better for
1020   // the current compilation.
1021   int _inline_depth;
1022 
1023   // utility methods to work on the speculative part of the type
1024   const TypePtr* dual_speculative() const;
1025   const TypePtr* xmeet_speculative(const TypePtr* other) const;
1026   bool eq_speculative(const TypePtr* other) const;
1027   int hash_speculative() const;
1028   const TypePtr* add_offset_speculative(intptr_t offset) const;
1029   const TypePtr* with_offset_speculative(intptr_t offset) const;
1030 #ifndef PRODUCT
1031   void dump_speculative(outputStream *st) const;
1032 #endif
1033 
1034   // utility methods to work on the inline depth of the type
1035   int dual_inline_depth() const;
1036   int meet_inline_depth(int depth) const;
1037 #ifndef PRODUCT
1038   void dump_inline_depth(outputStream *st) const;
1039 #endif
1040 
1041   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1042   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1043   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1044   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1045   // encountered so the right logic specific to klasses or oops can be executed.,
1046   enum MeetResult {
1047     QUICK,
1048     UNLOADED,
1049     SUBTYPE,
1050     NOT_SUBTYPE,
1051     LCA
1052   };
1053   template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1054                                                             const T* other_type, ciKlass*& res_klass, bool& res_xk, bool& res_flat_array);
1055  private:
1056   template<class T> static bool is_meet_subtype_of(const T* sub_type, const T* super_type);
1057  protected:
1058 
1059   template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1060                                                   ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool &res_not_flat, bool &res_not_null_free);
1061 
1062   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);
1063   template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1064   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);
1065   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);
1066   template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1067   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);
1068   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);
1069   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);
1070 public:
1071   const Offset _offset;         // Offset into oop, with TOP & BOT
1072   const PTR _ptr;               // Pointer equivalence class
1073 
1074   int offset() const { return _offset.get(); }
1075   PTR ptr()    const { return _ptr; }
1076 
1077   static const TypePtr* make(TYPES t, PTR ptr, Offset offset,
1078                              const TypePtr* speculative = nullptr,
1079                              int inline_depth = InlineDepthBottom);
1080 
1081   // Return a 'ptr' version of this type
1082   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1083 
1084   virtual intptr_t get_con() const;
1085 
1086   Type::Offset xadd_offset(intptr_t offset) const;
1087   virtual const TypePtr* add_offset(intptr_t offset) const;
1088   virtual const TypePtr* with_offset(intptr_t offset) const;
1089   virtual int flat_offset() const { return offset(); }
1090   virtual bool eq(const Type *t) const;
1091   virtual uint hash() const;             // Type specific hashing
1092 
1093   virtual bool singleton(void) const;    // TRUE if type is a singleton
1094   virtual bool empty(void) const;        // TRUE if type is vacuous
1095   virtual const Type *xmeet( const Type *t ) const;
1096   virtual const Type *xmeet_helper( const Type *t ) const;
1097   Offset meet_offset(int offset) const;
1098   Offset dual_offset() const;
1099   virtual const Type *xdual() const;    // Compute dual right now.
1100 
1101   // meet, dual and join over pointer equivalence sets
1102   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1103   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1104 
1105   // This is textually confusing unless one recalls that
1106   // join(t) == dual()->meet(t->dual())->dual().
1107   PTR join_ptr( const PTR in_ptr ) const {
1108     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1109   }
1110 
1111   // Speculative type helper methods.
1112   virtual const TypePtr* speculative() const { return _speculative; }
1113   int inline_depth() const                   { return _inline_depth; }
1114   virtual ciKlass* speculative_type() const;
1115   virtual ciKlass* speculative_type_not_null() const;
1116   virtual bool speculative_maybe_null() const;
1117   virtual bool speculative_always_null() const;
1118   virtual const TypePtr* remove_speculative() const;
1119   virtual const Type* cleanup_speculative() const;
1120   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1121   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1122   virtual const TypePtr* with_inline_depth(int depth) const;
1123 
1124   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1125 
1126   virtual bool can_be_inline_type() const { return false; }
1127   virtual bool flat_in_array()      const { return false; }
1128   virtual bool not_flat_in_array()  const { return true; }
1129   virtual bool is_flat()            const { return false; }
1130   virtual bool is_not_flat()        const { return false; }
1131   virtual bool is_null_free()       const { return false; }
1132   virtual bool is_not_null_free()   const { return false; }
1133 
1134   // Tests for relation to centerline of type lattice:
1135   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1136   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1137   // Convenience common pre-built types.
1138   static const TypePtr *NULL_PTR;
1139   static const TypePtr *NOTNULL;
1140   static const TypePtr *BOTTOM;
1141 #ifndef PRODUCT
1142   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1143 #endif
1144 };
1145 
1146 //------------------------------TypeRawPtr-------------------------------------
1147 // Class of raw pointers, pointers to things other than Oops.  Examples
1148 // include the stack pointer, top of heap, card-marking area, handles, etc.
1149 class TypeRawPtr : public TypePtr {
1150 protected:
1151   TypeRawPtr(PTR ptr, address bits) : TypePtr(RawPtr,ptr,Offset(0)), _bits(bits){}
1152 public:
1153   virtual bool eq( const Type *t ) const;
1154   virtual uint hash() const;    // Type specific hashing
1155 
1156   const address _bits;          // Constant value, if applicable
1157 
1158   static const TypeRawPtr *make( PTR ptr );
1159   static const TypeRawPtr *make( address bits );
1160 
1161   // Return a 'ptr' version of this type
1162   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1163 
1164   virtual intptr_t get_con() const;
1165 
1166   virtual const TypePtr* add_offset(intptr_t offset) const;
1167   virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1168 
1169   virtual const Type *xmeet( const Type *t ) const;
1170   virtual const Type *xdual() const;    // Compute dual right now.
1171   // Convenience common pre-built types.
1172   static const TypeRawPtr *BOTTOM;
1173   static const TypeRawPtr *NOTNULL;
1174 #ifndef PRODUCT
1175   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1176 #endif
1177 };
1178 
1179 //------------------------------TypeOopPtr-------------------------------------
1180 // Some kind of oop (Java pointer), either instance or array.
1181 class TypeOopPtr : public TypePtr {
1182   friend class TypeAry;
1183   friend class TypePtr;
1184   friend class TypeInstPtr;
1185   friend class TypeAryPtr;
1186 protected:
1187  TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset, int instance_id,
1188             const TypePtr* speculative, int inline_depth);
1189 public:
1190   virtual bool eq( const Type *t ) const;
1191   virtual uint hash() const;             // Type specific hashing
1192   virtual bool singleton(void) const;    // TRUE if type is a singleton
1193   enum {
1194    InstanceTop = -1,   // undefined instance
1195    InstanceBot = 0     // any possible instance
1196   };
1197 protected:
1198 
1199   // Oop is null, unless this is a constant oop.
1200   ciObject*     _const_oop;   // Constant oop
1201   // If _klass is null, then so is _sig.  This is an unloaded klass.
1202   ciKlass*      _klass;       // Klass object
1203 
1204   const TypeInterfaces* _interfaces;
1205 
1206   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1207   bool          _klass_is_exact;
1208   bool          _is_ptr_to_narrowoop;
1209   bool          _is_ptr_to_narrowklass;
1210   bool          _is_ptr_to_boxed_value;
1211 
1212   // If not InstanceTop or InstanceBot, indicates that this is
1213   // a particular instance of this type which is distinct.
1214   // This is the node index of the allocation node creating this instance.
1215   int           _instance_id;
1216 
1217   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1218 
1219   int dual_instance_id() const;
1220   int meet_instance_id(int uid) const;
1221 
1222   const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1223 
1224   // Do not allow interface-vs.-noninterface joins to collapse to top.
1225   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1226 
1227   virtual ciKlass* exact_klass_helper() const { return nullptr; }
1228   virtual ciKlass* klass() const { return _klass; }
1229 
1230 public:
1231 
1232   bool is_java_subtype_of(const TypeOopPtr* other) const {
1233     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1234   }
1235 
1236   bool is_same_java_type_as(const TypePtr* other) const {
1237     return is_same_java_type_as_helper(other->is_oopptr());
1238   }
1239 
1240   virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1241     ShouldNotReachHere(); return false;
1242   }
1243 
1244   bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1245     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1246   }
1247   virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1248   virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1249 
1250 
1251   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1252   // Respects UseUniqueSubclasses.
1253   // If the klass is final, the resulting type will be exact.
1254   static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1255     return make_from_klass_common(klass, true, false, interface_handling);
1256   }
1257   // Same as before, but will produce an exact type, even if
1258   // the klass is not final, as long as it has exactly one implementation.
1259   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1260     return make_from_klass_common(klass, true, true, interface_handling);
1261   }
1262   // Same as before, but does not respects UseUniqueSubclasses.
1263   // Use this only for creating array element types.
1264   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1265     return make_from_klass_common(klass, false, false, interface_handling);
1266   }
1267   // Creates a singleton type given an object.
1268   // If the object cannot be rendered as a constant,
1269   // may return a non-singleton type.
1270   // If require_constant, produce a null if a singleton is not possible.
1271   static const TypeOopPtr* make_from_constant(ciObject* o,
1272                                               bool require_constant = false);
1273 
1274   // Make a generic (unclassed) pointer to an oop.
1275   static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id,
1276                                 const TypePtr* speculative = nullptr,
1277                                 int inline_depth = InlineDepthBottom);
1278 
1279   ciObject* const_oop()    const { return _const_oop; }
1280   // Exact klass, possibly an interface or an array of interface
1281   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1282   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1283 
1284   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1285   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1286 
1287   // Returns true if this pointer points at memory which contains a
1288   // compressed oop references.
1289   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1290   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1291   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1292   bool is_known_instance()       const { return _instance_id > 0; }
1293   int  instance_id()             const { return _instance_id; }
1294   bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; }
1295 
1296   virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(_klass_is_exact)); }
1297   virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
1298 
1299   virtual intptr_t get_con() const;
1300 
1301   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1302 
1303   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1304 
1305   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1306 
1307   // corresponding pointer to klass, for a given instance
1308   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1309 
1310   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1311   virtual const TypePtr* add_offset(intptr_t offset) const;
1312 
1313   // Speculative type helper methods.
1314   virtual const TypeOopPtr* remove_speculative() const;
1315   virtual const Type* cleanup_speculative() const;
1316   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1317   virtual const TypePtr* with_inline_depth(int depth) const;
1318 
1319   virtual const TypePtr* with_instance_id(int instance_id) const;
1320 
1321   virtual const Type *xdual() const;    // Compute dual right now.
1322   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1323   virtual const Type *xmeet_helper(const Type *t) const;
1324 
1325   // Convenience common pre-built type.
1326   static const TypeOopPtr *BOTTOM;
1327 #ifndef PRODUCT
1328   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1329 #endif
1330 private:
1331   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1332     return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact());
1333   }
1334 
1335   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const {
1336     ShouldNotReachHere(); return false;
1337   }
1338 
1339   virtual const TypeInterfaces* interfaces() const {
1340     return _interfaces;
1341   };
1342 
1343   const TypeOopPtr* is_reference_type(const Type* other) const {
1344     return other->isa_oopptr();
1345   }
1346 
1347   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1348     return other->isa_aryptr();
1349   }
1350 
1351   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1352     return other->isa_instptr();
1353   }
1354 };
1355 
1356 //------------------------------TypeInstPtr------------------------------------
1357 // Class of Java object pointers, pointing either to non-array Java instances
1358 // or to a Klass* (including array klasses).
1359 class TypeInstPtr : public TypeOopPtr {
1360   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1361               bool flat_in_array, int instance_id, const TypePtr* speculative,
1362               int inline_depth);
1363   virtual bool eq( const Type *t ) const;
1364   virtual uint hash() const;             // Type specific hashing
1365   bool _flat_in_array; // Type is flat in arrays
1366   ciKlass* exact_klass_helper() const;
1367 
1368 public:
1369 
1370   // Instance klass, ignoring any interface
1371   ciInstanceKlass* instance_klass() const {
1372     assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1373     return klass()->as_instance_klass();
1374   }
1375 
1376   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1377   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1378   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1379 
1380   // Make a pointer to a constant oop.
1381   static const TypeInstPtr *make(ciObject* o) {
1382     ciKlass* k = o->klass();
1383     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1384     return make(TypePtr::Constant, k, interfaces, true, o, Offset(0));
1385   }
1386   // Make a pointer to a constant oop with offset.
1387   static const TypeInstPtr *make(ciObject* o, Offset offset) {
1388     ciKlass* k = o->klass();
1389     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1390     return make(TypePtr::Constant, k, interfaces, true, o, offset);
1391   }
1392 
1393   // Make a pointer to some value of type klass.
1394   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1395     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1396     return make(ptr, klass, interfaces, false, nullptr, Offset(0));
1397   }
1398 
1399   // Make a pointer to some non-polymorphic value of exactly type klass.
1400   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1401     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1402     return make(ptr, klass, interfaces, true, nullptr, Offset(0));
1403   }
1404 
1405   // Make a pointer to some value of type klass with offset.
1406   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, Offset offset) {
1407     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1408     return make(ptr, klass, interfaces, false, nullptr, offset);
1409   }
1410 
1411   // Make a pointer to an oop.
1412   static const TypeInstPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1413                                  bool flat_in_array = false,
1414                                  int instance_id = InstanceBot,
1415                                  const TypePtr* speculative = nullptr,
1416                                  int inline_depth = InlineDepthBottom);
1417 
1418   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, int instance_id = InstanceBot) {
1419     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1420     return make(ptr, k, interfaces, xk, o, offset, false, instance_id);
1421   }
1422 
1423   /** Create constant type for a constant boxed value */
1424   const Type* get_const_boxed_value() const;
1425 
1426   // If this is a java.lang.Class constant, return the type for it or null.
1427   // Pass to Type::get_const_type to turn it to a type, which will usually
1428   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1429   ciType* java_mirror_type(bool* is_null_free_array = nullptr) const;
1430 
1431   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1432 
1433   virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1434 
1435   virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1436 
1437   virtual const TypePtr* add_offset(intptr_t offset) const;
1438   virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1439 
1440   // Speculative type helper methods.
1441   virtual const TypeInstPtr* remove_speculative() const;
1442   const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1443   virtual const TypePtr* with_inline_depth(int depth) const;
1444   virtual const TypePtr* with_instance_id(int instance_id) const;
1445 
1446   virtual const TypeInstPtr* cast_to_flat_in_array() const;
1447   virtual bool flat_in_array() const { return _flat_in_array; }
1448   virtual bool not_flat_in_array() const { return !can_be_inline_type() || (_klass->is_inlinetype() && !flat_in_array()); }
1449 
1450   // the core of the computation of the meet of 2 types
1451   virtual const Type *xmeet_helper(const Type *t) const;
1452   virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1453   virtual const Type *xdual() const;    // Compute dual right now.
1454 
1455   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1456 
1457   virtual bool can_be_inline_array() const;
1458 
1459   // Convenience common pre-built types.
1460   static const TypeInstPtr *NOTNULL;
1461   static const TypeInstPtr *BOTTOM;
1462   static const TypeInstPtr *MIRROR;
1463   static const TypeInstPtr *MARK;
1464   static const TypeInstPtr *KLASS;
1465 #ifndef PRODUCT
1466   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1467 #endif
1468 
1469 private:
1470   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1471 
1472   virtual bool is_meet_same_type_as(const TypePtr* other) const {
1473     return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1474   }
1475 
1476 };
1477 
1478 //------------------------------TypeAryPtr-------------------------------------
1479 // Class of Java array pointers
1480 class TypeAryPtr : public TypeOopPtr {
1481   friend class Type;
1482   friend class TypePtr;
1483   friend class TypeInstPtr;
1484 
1485   TypeAryPtr(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1486              Offset offset, Offset field_offset, int instance_id, bool is_autobox_cache,
1487              const TypePtr* speculative, int inline_depth)
1488     : TypeOopPtr(AryPtr, ptr, k, _array_interfaces, xk, o, offset, field_offset, instance_id, speculative, inline_depth),
1489     _ary(ary),
1490     _is_autobox_cache(is_autobox_cache),
1491     _field_offset(field_offset)
1492  {
1493     int dummy;
1494     bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1495 
1496     if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1497         _offset.get() != 0 && _offset.get() != arrayOopDesc::length_offset_in_bytes() &&
1498         _offset.get() != arrayOopDesc::klass_offset_in_bytes()) {
1499       _is_ptr_to_narrowoop = true;
1500     }
1501 
1502   }
1503   virtual bool eq( const Type *t ) const;
1504   virtual uint hash() const;    // Type specific hashing
1505   const TypeAry *_ary;          // Array we point into
1506   const bool     _is_autobox_cache;
1507   // For flat inline type arrays, each field of the inline type in
1508   // the array has its own memory slice so we need to keep track of
1509   // which field is accessed
1510   const Offset _field_offset;
1511   Offset meet_field_offset(const Type::Offset offset) const;
1512   Offset dual_field_offset() const;
1513 
1514   ciKlass* compute_klass() const;
1515 
1516   // A pointer to delay allocation to Type::Initialize_shared()
1517 
1518   static const TypeInterfaces* _array_interfaces;
1519   ciKlass* exact_klass_helper() const;
1520   // Only guaranteed non null for array of basic types
1521   ciKlass* klass() const;
1522 
1523 public:
1524 
1525   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1526   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1527   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1528 
1529   // returns base element type, an instance klass (and not interface) for object arrays
1530   const Type* base_element_type(int& dims) const;
1531 
1532   // Accessors
1533   bool  is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1534 
1535   const TypeAry* ary() const  { return _ary; }
1536   const Type*    elem() const { return _ary->_elem; }
1537   const TypeInt* size() const { return _ary->_size; }
1538   bool      is_stable() const { return _ary->_stable; }
1539 
1540   // Inline type array properties
1541   bool is_flat()          const { return _ary->_flat; }
1542   bool is_not_flat()      const { return _ary->_not_flat; }
1543   bool is_null_free()     const { return _ary->_elem->make_ptr() != nullptr && (_ary->_elem->make_ptr()->ptr() == NotNull || _ary->_elem->make_ptr()->ptr() == AnyNull); }
1544   bool is_not_null_free() const { return _ary->_not_null_free; }
1545 
1546   bool is_autobox_cache() const { return _is_autobox_cache; }
1547 
1548   static const TypeAryPtr* make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1549                                 Offset field_offset = Offset::bottom,
1550                                 int instance_id = InstanceBot,
1551                                 const TypePtr* speculative = nullptr,
1552                                 int inline_depth = InlineDepthBottom);
1553   // Constant pointer to array
1554   static const TypeAryPtr* make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1555                                 Offset field_offset = Offset::bottom,
1556                                 int instance_id = InstanceBot,
1557                                 const TypePtr* speculative = nullptr,
1558                                 int inline_depth = InlineDepthBottom,
1559                                 bool is_autobox_cache = false);
1560 
1561   // Return a 'ptr' version of this type
1562   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1563 
1564   virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1565 
1566   virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1567 
1568   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1569   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1570 
1571   virtual bool empty(void) const;        // TRUE if type is vacuous
1572   virtual const TypePtr *add_offset( intptr_t offset ) const;
1573   virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1574   const TypeAryPtr* with_ary(const TypeAry* ary) const;
1575 
1576   // Speculative type helper methods.
1577   virtual const TypeAryPtr* remove_speculative() const;
1578   virtual const Type* cleanup_speculative() const;
1579   virtual const TypePtr* with_inline_depth(int depth) const;
1580   virtual const TypePtr* with_instance_id(int instance_id) const;
1581 
1582   // the core of the computation of the meet of 2 types
1583   virtual const Type *xmeet_helper(const Type *t) const;
1584   virtual const Type *xdual() const;    // Compute dual right now.
1585 
1586   // Inline type array properties
1587   const TypeAryPtr* cast_to_not_flat(bool not_flat = true) const;
1588   const TypeAryPtr* cast_to_not_null_free(bool not_null_free = true) const;
1589   const TypeAryPtr* update_properties(const TypeAryPtr* new_type) const;
1590   jint flat_layout_helper() const;
1591   int flat_elem_size() const;
1592   int flat_log_elem_size() const;
1593 
1594   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1595   int stable_dimension() const;
1596 
1597   const TypeAryPtr* cast_to_autobox_cache() const;
1598 
1599   static jint max_array_length(BasicType etype);
1600 
1601   int flat_offset() const;
1602   const Offset field_offset() const { return _field_offset; }
1603   const TypeAryPtr* with_field_offset(int offset) const;
1604   const TypePtr* add_field_offset_and_offset(intptr_t offset) const;
1605 
1606   virtual bool can_be_inline_type() const { return false; }
1607   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1608 
1609   virtual bool can_be_inline_array() const;
1610 
1611   // Convenience common pre-built types.
1612   static const TypeAryPtr* BOTTOM;
1613   static const TypeAryPtr *RANGE;
1614   static const TypeAryPtr *OOPS;
1615   static const TypeAryPtr *NARROWOOPS;
1616   static const TypeAryPtr *BYTES;
1617   static const TypeAryPtr *SHORTS;
1618   static const TypeAryPtr *CHARS;
1619   static const TypeAryPtr *INTS;
1620   static const TypeAryPtr *LONGS;
1621   static const TypeAryPtr *FLOATS;
1622   static const TypeAryPtr *DOUBLES;
1623   static const TypeAryPtr *INLINES;
1624   // selects one of the above:
1625   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1626     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1627     return _array_body_type[elem];
1628   }
1629   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1630   // sharpen the type of an int which is used as an array size
1631 #ifndef PRODUCT
1632   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1633 #endif
1634 private:
1635   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1636 };
1637 
1638 //------------------------------TypeMetadataPtr-------------------------------------
1639 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1640 class TypeMetadataPtr : public TypePtr {
1641 protected:
1642   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1643   // Do not allow interface-vs.-noninterface joins to collapse to top.
1644   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1645 public:
1646   virtual bool eq( const Type *t ) const;
1647   virtual uint hash() const;             // Type specific hashing
1648   virtual bool singleton(void) const;    // TRUE if type is a singleton
1649 
1650 private:
1651   ciMetadata*   _metadata;
1652 
1653 public:
1654   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, Offset offset);
1655 
1656   static const TypeMetadataPtr* make(ciMethod* m);
1657   static const TypeMetadataPtr* make(ciMethodData* m);
1658 
1659   ciMetadata* metadata() const { return _metadata; }
1660 
1661   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1662 
1663   virtual const TypePtr *add_offset( intptr_t offset ) const;
1664 
1665   virtual const Type *xmeet( const Type *t ) const;
1666   virtual const Type *xdual() const;    // Compute dual right now.
1667 
1668   virtual intptr_t get_con() const;
1669 
1670   // Convenience common pre-built types.
1671   static const TypeMetadataPtr *BOTTOM;
1672 
1673 #ifndef PRODUCT
1674   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1675 #endif
1676 };
1677 
1678 //------------------------------TypeKlassPtr-----------------------------------
1679 // Class of Java Klass pointers
1680 class TypeKlassPtr : public TypePtr {
1681   friend class TypeInstKlassPtr;
1682   friend class TypeAryKlassPtr;
1683   friend class TypePtr;
1684 protected:
1685   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset);
1686 
1687   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1688 
1689 public:
1690   virtual bool eq( const Type *t ) const;
1691   virtual uint hash() const;
1692   virtual bool singleton(void) const;    // TRUE if type is a singleton
1693 
1694 protected:
1695 
1696   ciKlass* _klass;
1697   const TypeInterfaces* _interfaces;
1698   const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1699   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1700   virtual ciKlass* exact_klass_helper() const;
1701   virtual ciKlass* klass() const { return  _klass; }
1702 
1703 public:
1704 
1705   bool is_java_subtype_of(const TypeKlassPtr* other) const {
1706     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1707   }
1708   bool is_same_java_type_as(const TypePtr* other) const {
1709     return is_same_java_type_as_helper(other->is_klassptr());
1710   }
1711 
1712   bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1713     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1714   }
1715   virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1716   virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1717   virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1718 
1719   // Exact klass, possibly an interface or an array of interface
1720   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1721   virtual bool klass_is_exact()    const { return _ptr == Constant; }
1722 
1723   static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1724   static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling = ignore_interfaces);
1725 
1726   virtual bool  is_loaded() const { return _klass->is_loaded(); }
1727 
1728   virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1729 
1730   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1731 
1732   // corresponding pointer to instance, for a given class
1733   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1734 
1735   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1736   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1737   virtual const Type    *xdual() const { ShouldNotReachHere(); return nullptr; }
1738 
1739   virtual intptr_t get_con() const;
1740 
1741   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1742 
1743   virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
1744 
1745   virtual bool not_flat_in_array_inexact() const {
1746     return true;
1747   }
1748 
1749   virtual const TypeKlassPtr* try_improve() const { return this; }
1750 
1751 #ifndef PRODUCT
1752   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1753 #endif
1754 private:
1755   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1756     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1757   }
1758 
1759   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1760     ShouldNotReachHere(); return false;
1761   }
1762 
1763   virtual const TypeInterfaces* interfaces() const {
1764     return _interfaces;
1765   };
1766 
1767   const TypeKlassPtr* is_reference_type(const Type* other) const {
1768     return other->isa_klassptr();
1769   }
1770 
1771   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1772     return other->isa_aryklassptr();
1773   }
1774 
1775   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1776     return other->isa_instklassptr();
1777   }
1778 };
1779 
1780 // Instance klass pointer, mirrors TypeInstPtr
1781 class TypeInstKlassPtr : public TypeKlassPtr {
1782 
1783   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array)
1784     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset), _flat_in_array(flat_in_array) {
1785     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1786   }
1787 
1788   virtual bool must_be_exact() const;
1789 
1790   const bool _flat_in_array; // Type is flat in arrays
1791 
1792 public:
1793   // Instance klass ignoring any interface
1794   ciInstanceKlass* instance_klass() const {
1795     assert(!klass()->is_interface(), "");
1796     return klass()->as_instance_klass();
1797   }
1798 
1799   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1800   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1801   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1802 
1803   virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(klass_is_exact())); }
1804 
1805   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1806     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1807     return make(TypePtr::Constant, k, interfaces, Offset(0));
1808   }
1809   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array = false);
1810 
1811   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, Offset offset) {
1812     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1813     return make(ptr, k, interfaces, offset);
1814   }
1815 
1816   virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1817 
1818   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1819 
1820   // corresponding pointer to instance, for a given class
1821   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1822   virtual uint hash() const;
1823   virtual bool eq(const Type *t) const;
1824 
1825   virtual const TypePtr *add_offset( intptr_t offset ) const;
1826   virtual const Type    *xmeet( const Type *t ) const;
1827   virtual const Type    *xdual() const;
1828   virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1829 
1830   virtual const TypeKlassPtr* try_improve() const;
1831 
1832   virtual bool flat_in_array() const { return _flat_in_array; }
1833 
1834   // Checks if this klass pointer is not flat in array by also considering exactness information.
1835   virtual bool not_flat_in_array() const {
1836     return !_klass->can_be_inline_klass(klass_is_exact()) || (_klass->is_inlinetype() && !flat_in_array());
1837   }
1838 
1839   // not_flat_in_array() version that assumes that the klass is inexact. This is used for sub type checks where the
1840   // super klass is always an exact klass constant (and thus possibly known to be not flat in array), while a sub
1841   // klass could very well be flat in array:
1842   //
1843   //           MyValue       <:       Object
1844   //        flat in array       not flat in array
1845   //
1846   // Thus, this version checks if we know that the klass is not flat in array even if it's not exact.
1847   virtual bool not_flat_in_array_inexact() const {
1848     return !_klass->can_be_inline_klass() || (_klass->is_inlinetype() && !flat_in_array());
1849   }
1850 
1851   virtual bool can_be_inline_array() const;
1852 
1853   // Convenience common pre-built types.
1854   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1855   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1856 private:
1857   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1858 };
1859 
1860 // Array klass pointer, mirrors TypeAryPtr
1861 class TypeAryKlassPtr : public TypeKlassPtr {
1862   friend class TypeInstKlassPtr;
1863   friend class Type;
1864   friend class TypePtr;
1865 
1866   const Type *_elem;
1867   const bool _not_flat;      // Array is never flat
1868   const bool _not_null_free; // Array is never null-free
1869   const bool _flat;
1870   const bool _null_free;
1871 
1872   static const TypeInterfaces* _array_interfaces;
1873   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, Offset offset, bool not_flat, int not_null_free, bool flat, bool null_free)
1874     : 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) {
1875     assert(klass == nullptr || klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1876   }
1877 
1878   virtual ciKlass* exact_klass_helper() const;
1879   // Only guaranteed non null for array of basic types
1880   virtual ciKlass* klass() const;
1881 
1882   virtual bool must_be_exact() const;
1883 
1884   bool dual_flat() const {
1885     return _flat;
1886   }
1887 
1888   bool meet_flat(bool other) const {
1889     return _flat && other;
1890   }
1891 
1892   bool dual_null_free() const {
1893     return _null_free;
1894   }
1895 
1896   bool meet_null_free(bool other) const {
1897     return _null_free && other;
1898   }
1899 
1900 public:
1901 
1902   // returns base element type, an instance klass (and not interface) for object arrays
1903   const Type* base_element_type(int& dims) const;
1904 
1905   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);
1906 
1907   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1908   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1909   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1910 
1911   bool  is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1912 
1913   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);
1914   static const TypeAryKlassPtr* make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling);
1915   static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1916 
1917   const Type *elem() const { return _elem; }
1918 
1919   virtual bool eq(const Type *t) const;
1920   virtual uint hash() const;             // Type specific hashing
1921 
1922   virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
1923 
1924   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1925 
1926   const TypeAryKlassPtr* cast_to_null_free() const;
1927 
1928   // corresponding pointer to instance, for a given class
1929   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1930 
1931   virtual const TypePtr *add_offset( intptr_t offset ) const;
1932   virtual const Type    *xmeet( const Type *t ) const;
1933   virtual const Type    *xdual() const;      // Compute dual right now.
1934 
1935   virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
1936 
1937   virtual bool empty(void) const {
1938     return TypeKlassPtr::empty() || _elem->empty();
1939   }
1940 
1941   bool is_flat()          const { return _flat; }
1942   bool is_not_flat()      const { return _not_flat; }
1943   bool is_null_free()     const { return _null_free; }
1944   bool is_not_null_free() const { return _not_null_free; }
1945   virtual bool can_be_inline_array() const;
1946 
1947 #ifndef PRODUCT
1948   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1949 #endif
1950 private:
1951   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1952 };
1953 
1954 class TypeNarrowPtr : public Type {
1955 protected:
1956   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1957 
1958   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1959                                                   _ptrtype(ptrtype) {
1960     assert(ptrtype->offset() == 0 ||
1961            ptrtype->offset() == OffsetBot ||
1962            ptrtype->offset() == OffsetTop, "no real offsets");
1963   }
1964 
1965   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1966   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1967   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1968   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1969   // Do not allow interface-vs.-noninterface joins to collapse to top.
1970   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1971 public:
1972   virtual bool eq( const Type *t ) const;
1973   virtual uint hash() const;             // Type specific hashing
1974   virtual bool singleton(void) const;    // TRUE if type is a singleton
1975 
1976   virtual const Type *xmeet( const Type *t ) const;
1977   virtual const Type *xdual() const;    // Compute dual right now.
1978 
1979   virtual intptr_t get_con() const;
1980 
1981   virtual bool empty(void) const;        // TRUE if type is vacuous
1982 
1983   // returns the equivalent ptr type for this compressed pointer
1984   const TypePtr *get_ptrtype() const {
1985     return _ptrtype;
1986   }
1987 
1988   bool is_known_instance() const {
1989     return _ptrtype->is_known_instance();
1990   }
1991 
1992 #ifndef PRODUCT
1993   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1994 #endif
1995 };
1996 
1997 //------------------------------TypeNarrowOop----------------------------------
1998 // A compressed reference to some kind of Oop.  This type wraps around
1999 // a preexisting TypeOopPtr and forwards most of it's operations to
2000 // the underlying type.  It's only real purpose is to track the
2001 // oopness of the compressed oop value when we expose the conversion
2002 // between the normal and the compressed form.
2003 class TypeNarrowOop : public TypeNarrowPtr {
2004 protected:
2005   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
2006   }
2007 
2008   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2009     return t->isa_narrowoop();
2010   }
2011 
2012   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2013     return t->is_narrowoop();
2014   }
2015 
2016   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2017     return new TypeNarrowOop(t);
2018   }
2019 
2020   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2021     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
2022   }
2023 
2024 public:
2025 
2026   static const TypeNarrowOop *make( const TypePtr* type);
2027 
2028   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
2029     return make(TypeOopPtr::make_from_constant(con, require_constant));
2030   }
2031 
2032   static const TypeNarrowOop *BOTTOM;
2033   static const TypeNarrowOop *NULL_PTR;
2034 
2035   virtual const TypeNarrowOop* remove_speculative() const;
2036   virtual const Type* cleanup_speculative() const;
2037 
2038 #ifndef PRODUCT
2039   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2040 #endif
2041 };
2042 
2043 //------------------------------TypeNarrowKlass----------------------------------
2044 // A compressed reference to klass pointer.  This type wraps around a
2045 // preexisting TypeKlassPtr and forwards most of it's operations to
2046 // the underlying type.
2047 class TypeNarrowKlass : public TypeNarrowPtr {
2048 protected:
2049   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
2050   }
2051 
2052   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2053     return t->isa_narrowklass();
2054   }
2055 
2056   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2057     return t->is_narrowklass();
2058   }
2059 
2060   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2061     return new TypeNarrowKlass(t);
2062   }
2063 
2064   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2065     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2066   }
2067 
2068 public:
2069   static const TypeNarrowKlass *make( const TypePtr* type);
2070 
2071   // static const TypeNarrowKlass *BOTTOM;
2072   static const TypeNarrowKlass *NULL_PTR;
2073 
2074 #ifndef PRODUCT
2075   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2076 #endif
2077 };
2078 
2079 //------------------------------TypeFunc---------------------------------------
2080 // Class of Array Types
2081 class TypeFunc : public Type {
2082   TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc)
2083     : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {}
2084   virtual bool eq( const Type *t ) const;
2085   virtual uint hash() const;             // Type specific hashing
2086   virtual bool singleton(void) const;    // TRUE if type is a singleton
2087   virtual bool empty(void) const;        // TRUE if type is vacuous
2088 
2089   // Domains of inputs: inline type arguments are not passed by
2090   // reference, instead each field of the inline type is passed as an
2091   // argument. We maintain 2 views of the argument list here: one
2092   // based on the signature (with an inline type argument as a single
2093   // slot), one based on the actual calling convention (with a value
2094   // type argument as a list of its fields).
2095   const TypeTuple* const _domain_sig;
2096   const TypeTuple* const _domain_cc;
2097   // Range of results. Similar to domains: an inline type result can be
2098   // returned in registers in which case range_cc lists all fields and
2099   // is the actual calling convention.
2100   const TypeTuple* const _range_sig;
2101   const TypeTuple* const _range_cc;
2102 
2103 public:
2104   // Constants are shared among ADLC and VM
2105   enum { Control    = AdlcVMDeps::Control,
2106          I_O        = AdlcVMDeps::I_O,
2107          Memory     = AdlcVMDeps::Memory,
2108          FramePtr   = AdlcVMDeps::FramePtr,
2109          ReturnAdr  = AdlcVMDeps::ReturnAdr,
2110          Parms      = AdlcVMDeps::Parms
2111   };
2112 
2113 
2114   // Accessors:
2115   const TypeTuple* domain_sig() const { return _domain_sig; }
2116   const TypeTuple* domain_cc()  const { return _domain_cc; }
2117   const TypeTuple* range_sig()  const { return _range_sig; }
2118   const TypeTuple* range_cc()   const { return _range_cc; }
2119 
2120   static const TypeFunc* make(ciMethod* method, bool is_osr_compilation = false);
2121   static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
2122                               const TypeTuple* range_sig, const TypeTuple* range_cc);
2123   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2124 
2125   virtual const Type *xmeet( const Type *t ) const;
2126   virtual const Type *xdual() const;    // Compute dual right now.
2127 
2128   BasicType return_type() const;
2129 
2130   bool returns_inline_type_as_fields() const { return range_sig() != range_cc(); }
2131 
2132 #ifndef PRODUCT
2133   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2134 #endif
2135   // Convenience common pre-built types.
2136 };
2137 
2138 //------------------------------accessors--------------------------------------
2139 inline bool Type::is_ptr_to_narrowoop() const {
2140 #ifdef _LP64
2141   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2142 #else
2143   return false;
2144 #endif
2145 }
2146 
2147 inline bool Type::is_ptr_to_narrowklass() const {
2148 #ifdef _LP64
2149   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2150 #else
2151   return false;
2152 #endif
2153 }
2154 
2155 inline float Type::getf() const {
2156   assert( _base == FloatCon, "Not a FloatCon" );
2157   return ((TypeF*)this)->_f;
2158 }
2159 
2160 inline short Type::geth() const {
2161   assert(_base == HalfFloatCon, "Not a HalfFloatCon");
2162   return ((TypeH*)this)->_f;
2163 }
2164 
2165 inline double Type::getd() const {
2166   assert( _base == DoubleCon, "Not a DoubleCon" );
2167   return ((TypeD*)this)->_d;
2168 }
2169 
2170 inline const TypeInteger *Type::is_integer(BasicType bt) const {
2171   assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int");
2172   return (TypeInteger*)this;
2173 }
2174 
2175 inline const TypeInteger *Type::isa_integer(BasicType bt) const {
2176   return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : nullptr);
2177 }
2178 
2179 inline const TypeInt *Type::is_int() const {
2180   assert( _base == Int, "Not an Int" );
2181   return (TypeInt*)this;
2182 }
2183 
2184 inline const TypeInt *Type::isa_int() const {
2185   return ( _base == Int ? (TypeInt*)this : nullptr);
2186 }
2187 
2188 inline const TypeLong *Type::is_long() const {
2189   assert( _base == Long, "Not a Long" );
2190   return (TypeLong*)this;
2191 }
2192 
2193 inline const TypeLong *Type::isa_long() const {
2194   return ( _base == Long ? (TypeLong*)this : nullptr);
2195 }
2196 
2197 inline const TypeH* Type::isa_half_float() const {
2198   return ((_base == HalfFloatTop ||
2199            _base == HalfFloatCon ||
2200            _base == HalfFloatBot) ? (TypeH*)this : nullptr);
2201 }
2202 
2203 inline const TypeH* Type::is_half_float_constant() const {
2204   assert( _base == HalfFloatCon, "Not a HalfFloat" );
2205   return (TypeH*)this;
2206 }
2207 
2208 inline const TypeH* Type::isa_half_float_constant() const {
2209   return (_base == HalfFloatCon ? (TypeH*)this : nullptr);
2210 }
2211 
2212 inline const TypeF *Type::isa_float() const {
2213   return ((_base == FloatTop ||
2214            _base == FloatCon ||
2215            _base == FloatBot) ? (TypeF*)this : nullptr);
2216 }
2217 
2218 inline const TypeF *Type::is_float_constant() const {
2219   assert( _base == FloatCon, "Not a Float" );
2220   return (TypeF*)this;
2221 }
2222 
2223 inline const TypeF *Type::isa_float_constant() const {
2224   return ( _base == FloatCon ? (TypeF*)this : nullptr);
2225 }
2226 
2227 inline const TypeD *Type::isa_double() const {
2228   return ((_base == DoubleTop ||
2229            _base == DoubleCon ||
2230            _base == DoubleBot) ? (TypeD*)this : nullptr);
2231 }
2232 
2233 inline const TypeD *Type::is_double_constant() const {
2234   assert( _base == DoubleCon, "Not a Double" );
2235   return (TypeD*)this;
2236 }
2237 
2238 inline const TypeD *Type::isa_double_constant() const {
2239   return ( _base == DoubleCon ? (TypeD*)this : nullptr);
2240 }
2241 
2242 inline const TypeTuple *Type::is_tuple() const {
2243   assert( _base == Tuple, "Not a Tuple" );
2244   return (TypeTuple*)this;
2245 }
2246 
2247 inline const TypeAry *Type::is_ary() const {
2248   assert( _base == Array , "Not an Array" );
2249   return (TypeAry*)this;
2250 }
2251 
2252 inline const TypeAry *Type::isa_ary() const {
2253   return ((_base == Array) ? (TypeAry*)this : nullptr);
2254 }
2255 
2256 inline const TypeVectMask *Type::is_vectmask() const {
2257   assert( _base == VectorMask, "Not a Vector Mask" );
2258   return (TypeVectMask*)this;
2259 }
2260 
2261 inline const TypeVectMask *Type::isa_vectmask() const {
2262   return (_base == VectorMask) ? (TypeVectMask*)this : nullptr;
2263 }
2264 
2265 inline const TypeVect *Type::is_vect() const {
2266   assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" );
2267   return (TypeVect*)this;
2268 }
2269 
2270 inline const TypeVect *Type::isa_vect() const {
2271   return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : nullptr;
2272 }
2273 
2274 inline const TypePtr *Type::is_ptr() const {
2275   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2276   assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer");
2277   return (TypePtr*)this;
2278 }
2279 
2280 inline const TypePtr *Type::isa_ptr() const {
2281   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2282   return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : nullptr;
2283 }
2284 
2285 inline const TypeOopPtr *Type::is_oopptr() const {
2286   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2287   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
2288   return (TypeOopPtr*)this;
2289 }
2290 
2291 inline const TypeOopPtr *Type::isa_oopptr() const {
2292   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2293   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : nullptr;
2294 }
2295 
2296 inline const TypeRawPtr *Type::isa_rawptr() const {
2297   return (_base == RawPtr) ? (TypeRawPtr*)this : nullptr;
2298 }
2299 
2300 inline const TypeRawPtr *Type::is_rawptr() const {
2301   assert( _base == RawPtr, "Not a raw pointer" );
2302   return (TypeRawPtr*)this;
2303 }
2304 
2305 inline const TypeInstPtr *Type::isa_instptr() const {
2306   return (_base == InstPtr) ? (TypeInstPtr*)this : nullptr;
2307 }
2308 
2309 inline const TypeInstPtr *Type::is_instptr() const {
2310   assert( _base == InstPtr, "Not an object pointer" );
2311   return (TypeInstPtr*)this;
2312 }
2313 
2314 inline const TypeAryPtr *Type::isa_aryptr() const {
2315   return (_base == AryPtr) ? (TypeAryPtr*)this : nullptr;
2316 }
2317 
2318 inline const TypeAryPtr *Type::is_aryptr() const {
2319   assert( _base == AryPtr, "Not an array pointer" );
2320   return (TypeAryPtr*)this;
2321 }
2322 
2323 inline const TypeNarrowOop *Type::is_narrowoop() const {
2324   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2325   assert(_base == NarrowOop, "Not a narrow oop" ) ;
2326   return (TypeNarrowOop*)this;
2327 }
2328 
2329 inline const TypeNarrowOop *Type::isa_narrowoop() const {
2330   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2331   return (_base == NarrowOop) ? (TypeNarrowOop*)this : nullptr;
2332 }
2333 
2334 inline const TypeNarrowKlass *Type::is_narrowklass() const {
2335   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
2336   return (TypeNarrowKlass*)this;
2337 }
2338 
2339 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
2340   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : nullptr;
2341 }
2342 
2343 inline const TypeMetadataPtr *Type::is_metadataptr() const {
2344   // MetadataPtr is the first and CPCachePtr the last
2345   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
2346   return (TypeMetadataPtr*)this;
2347 }
2348 
2349 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
2350   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : nullptr;
2351 }
2352 
2353 inline const TypeKlassPtr *Type::isa_klassptr() const {
2354   return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : nullptr;
2355 }
2356 
2357 inline const TypeKlassPtr *Type::is_klassptr() const {
2358   assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer");
2359   return (TypeKlassPtr*)this;
2360 }
2361 
2362 inline const TypeInstKlassPtr *Type::isa_instklassptr() const {
2363   return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : nullptr;
2364 }
2365 
2366 inline const TypeInstKlassPtr *Type::is_instklassptr() const {
2367   assert(_base == InstKlassPtr, "Not a klass pointer");
2368   return (TypeInstKlassPtr*)this;
2369 }
2370 
2371 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const {
2372   return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : nullptr;
2373 }
2374 
2375 inline const TypeAryKlassPtr *Type::is_aryklassptr() const {
2376   assert(_base == AryKlassPtr, "Not a klass pointer");
2377   return (TypeAryKlassPtr*)this;
2378 }
2379 
2380 inline const TypePtr* Type::make_ptr() const {
2381   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
2382                               ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
2383                                                        isa_ptr());
2384 }
2385 
2386 inline const TypeOopPtr* Type::make_oopptr() const {
2387   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
2388 }
2389 
2390 inline const TypeNarrowOop* Type::make_narrowoop() const {
2391   return (_base == NarrowOop) ? is_narrowoop() :
2392                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2393 }
2394 
2395 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2396   return (_base == NarrowKlass) ? is_narrowklass() :
2397                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2398 }
2399 
2400 inline bool Type::is_floatingpoint() const {
2401   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2402       (_base == FloatCon)  || (_base == FloatBot) ||
2403       (_base == DoubleCon) || (_base == DoubleBot) )
2404     return true;
2405   return false;
2406 }
2407 
2408 inline bool Type::is_inlinetypeptr() const {
2409   return isa_instptr() != nullptr && is_instptr()->instance_klass()->is_inlinetype();
2410 }
2411 
2412 inline ciInlineKlass* Type::inline_klass() const {
2413   return make_ptr()->is_instptr()->instance_klass()->as_inline_klass();
2414 }
2415 
2416 template <>
2417 inline const TypeInt* Type::cast<TypeInt>() const {
2418   return is_int();
2419 }
2420 
2421 template <>
2422 inline const TypeLong* Type::cast<TypeLong>() const {
2423   return is_long();
2424 }
2425 
2426 // ===============================================================
2427 // Things that need to be 64-bits in the 64-bit build but
2428 // 32-bits in the 32-bit build.  Done this way to get full
2429 // optimization AND strong typing.
2430 #ifdef _LP64
2431 
2432 // For type queries and asserts
2433 #define is_intptr_t  is_long
2434 #define isa_intptr_t isa_long
2435 #define find_intptr_t_type find_long_type
2436 #define find_intptr_t_con  find_long_con
2437 #define TypeX        TypeLong
2438 #define Type_X       Type::Long
2439 #define TypeX_X      TypeLong::LONG
2440 #define TypeX_ZERO   TypeLong::ZERO
2441 // For 'ideal_reg' machine registers
2442 #define Op_RegX      Op_RegL
2443 // For phase->intcon variants
2444 #define MakeConX     longcon
2445 #define ConXNode     ConLNode
2446 // For array index arithmetic
2447 #define MulXNode     MulLNode
2448 #define AndXNode     AndLNode
2449 #define OrXNode      OrLNode
2450 #define CmpXNode     CmpLNode
2451 #define CmpUXNode    CmpULNode
2452 #define SubXNode     SubLNode
2453 #define LShiftXNode  LShiftLNode
2454 // For object size computation:
2455 #define AddXNode     AddLNode
2456 #define RShiftXNode  RShiftLNode
2457 // For card marks and hashcodes
2458 #define URShiftXNode URShiftLNode
2459 // For shenandoahSupport
2460 #define LoadXNode    LoadLNode
2461 #define StoreXNode   StoreLNode
2462 // Opcodes
2463 #define Op_LShiftX   Op_LShiftL
2464 #define Op_AndX      Op_AndL
2465 #define Op_AddX      Op_AddL
2466 #define Op_SubX      Op_SubL
2467 #define Op_XorX      Op_XorL
2468 #define Op_URShiftX  Op_URShiftL
2469 #define Op_LoadX     Op_LoadL
2470 #define Op_StoreX    Op_StoreL
2471 // conversions
2472 #define ConvI2X(x)   ConvI2L(x)
2473 #define ConvL2X(x)   (x)
2474 #define ConvX2I(x)   ConvL2I(x)
2475 #define ConvX2L(x)   (x)
2476 #define ConvX2UL(x)  (x)
2477 
2478 #else
2479 
2480 // For type queries and asserts
2481 #define is_intptr_t  is_int
2482 #define isa_intptr_t isa_int
2483 #define find_intptr_t_type find_int_type
2484 #define find_intptr_t_con  find_int_con
2485 #define TypeX        TypeInt
2486 #define Type_X       Type::Int
2487 #define TypeX_X      TypeInt::INT
2488 #define TypeX_ZERO   TypeInt::ZERO
2489 // For 'ideal_reg' machine registers
2490 #define Op_RegX      Op_RegI
2491 // For phase->intcon variants
2492 #define MakeConX     intcon
2493 #define ConXNode     ConINode
2494 // For array index arithmetic
2495 #define MulXNode     MulINode
2496 #define AndXNode     AndINode
2497 #define OrXNode      OrINode
2498 #define CmpXNode     CmpINode
2499 #define CmpUXNode    CmpUNode
2500 #define SubXNode     SubINode
2501 #define LShiftXNode  LShiftINode
2502 // For object size computation:
2503 #define AddXNode     AddINode
2504 #define RShiftXNode  RShiftINode
2505 // For card marks and hashcodes
2506 #define URShiftXNode URShiftINode
2507 // For shenandoahSupport
2508 #define LoadXNode    LoadINode
2509 #define StoreXNode   StoreINode
2510 // Opcodes
2511 #define Op_LShiftX   Op_LShiftI
2512 #define Op_AndX      Op_AndI
2513 #define Op_AddX      Op_AddI
2514 #define Op_SubX      Op_SubI
2515 #define Op_XorX      Op_XorI
2516 #define Op_URShiftX  Op_URShiftI
2517 #define Op_LoadX     Op_LoadI
2518 #define Op_StoreX    Op_StoreI
2519 // conversions
2520 #define ConvI2X(x)   (x)
2521 #define ConvL2X(x)   ConvL2I(x)
2522 #define ConvX2I(x)   (x)
2523 #define ConvX2L(x)   ConvI2L(x)
2524 #define ConvX2UL(x)  ConvI2UL(x)
2525 
2526 #endif
2527 
2528 #endif // SHARE_OPTO_TYPE_HPP