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