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   static const TypeInteger* make(jlong con, BasicType bt);
 610 
 611   static const TypeInteger* bottom(BasicType type);
 612   static const TypeInteger* zero(BasicType type);
 613   static const TypeInteger* one(BasicType type);
 614   static const TypeInteger* minus_1(BasicType type);
 615 };
 616 
 617 
 618 
 619 //------------------------------TypeInt----------------------------------------
 620 // Class of integer ranges, the set of integers between a lower bound and an
 621 // upper bound, inclusive.
 622 class TypeInt : public TypeInteger {
 623   TypeInt( jint lo, jint hi, int w );
 624 protected:
 625   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
 626 
 627 public:
 628   typedef jint NativeType;
 629   virtual bool eq( const Type *t ) const;
 630   virtual uint hash() const;             // Type specific hashing
 631   virtual bool singleton(void) const;    // TRUE if type is a singleton
 632   virtual bool empty(void) const;        // TRUE if type is vacuous
 633   const jint _lo, _hi;          // Lower bound, upper bound
 634 
 635   static const TypeInt *make(jint lo);
 636   // must always specify w
 637   static const TypeInt *make(jint lo, jint hi, int w);
 638 
 639   // Check for single integer
 640   bool is_con() const { return _lo==_hi; }
 641   bool is_con(jint i) const { return is_con() && _lo == i; }
 642   jint get_con() const { assert(is_con(), "" );  return _lo; }
 643 
 644   virtual bool        is_finite() const;  // Has a finite value
 645 
 646   virtual const Type *xmeet( const Type *t ) const;
 647   virtual const Type *xdual() const;    // Compute dual right now.
 648   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
 649   virtual const Type *narrow( const Type *t ) const;
 650 
 651   virtual jlong hi_as_long() const { return _hi; }
 652   virtual jlong lo_as_long() const { return _lo; }
 653 
 654   // Do not kill _widen bits.
 655   // Convenience common pre-built types.
 656   static const TypeInt *MAX;
 657   static const TypeInt *MIN;
 658   static const TypeInt *MINUS_1;
 659   static const TypeInt *ZERO;
 660   static const TypeInt *ONE;
 661   static const TypeInt *BOOL;
 662   static const TypeInt *CC;
 663   static const TypeInt *CC_LT;  // [-1]  == MINUS_1
 664   static const TypeInt *CC_GT;  // [1]   == ONE
 665   static const TypeInt *CC_EQ;  // [0]   == ZERO
 666   static const TypeInt *CC_LE;  // [-1,0]
 667   static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
 668   static const TypeInt *BYTE;
 669   static const TypeInt *UBYTE;
 670   static const TypeInt *CHAR;
 671   static const TypeInt *SHORT;
 672   static const TypeInt *POS;
 673   static const TypeInt *POS1;
 674   static const TypeInt *INT;
 675   static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
 676   static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT
 677 
 678   static const TypeInt *as_self(const Type *t) { return t->is_int(); }
 679 #ifndef PRODUCT
 680   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 681 #endif
 682 };
 683 
 684 
 685 //------------------------------TypeLong---------------------------------------
 686 // Class of long integer ranges, the set of integers between a lower bound and
 687 // an upper bound, inclusive.
 688 class TypeLong : public TypeInteger {
 689   TypeLong( jlong lo, jlong hi, int w );
 690 protected:
 691   // Do not kill _widen bits.
 692   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
 693 public:
 694   typedef jlong NativeType;
 695   virtual bool eq( const Type *t ) const;
 696   virtual uint hash() const;             // Type specific hashing
 697   virtual bool singleton(void) const;    // TRUE if type is a singleton
 698   virtual bool empty(void) const;        // TRUE if type is vacuous
 699 public:
 700   const jlong _lo, _hi;         // Lower bound, upper bound
 701 
 702   static const TypeLong *make(jlong lo);
 703   // must always specify w
 704   static const TypeLong *make(jlong lo, jlong hi, int w);
 705 
 706   // Check for single integer
 707   bool is_con() const { return _lo==_hi; }
 708   bool is_con(jlong i) const { return is_con() && _lo == i; }
 709   jlong get_con() const { assert(is_con(), "" ); return _lo; }
 710 
 711   // Check for positive 32-bit value.
 712   int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
 713 
 714   virtual bool        is_finite() const;  // Has a finite value
 715 
 716   virtual jlong hi_as_long() const { return _hi; }
 717   virtual jlong lo_as_long() const { return _lo; }
 718 
 719   virtual const Type *xmeet( const Type *t ) const;
 720   virtual const Type *xdual() const;    // Compute dual right now.
 721   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
 722   virtual const Type *narrow( const Type *t ) const;
 723   // Convenience common pre-built types.
 724   static const TypeLong *MAX;
 725   static const TypeLong *MIN;
 726   static const TypeLong *MINUS_1;
 727   static const TypeLong *ZERO;
 728   static const TypeLong *ONE;
 729   static const TypeLong *POS;
 730   static const TypeLong *LONG;
 731   static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
 732   static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
 733   static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG
 734 
 735   // static convenience methods.
 736   static const TypeLong *as_self(const Type *t) { return t->is_long(); }
 737 
 738 #ifndef PRODUCT
 739   virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
 740 #endif
 741 };
 742 
 743 //------------------------------TypeTuple--------------------------------------
 744 // Class of Tuple Types, essentially type collections for function signatures
 745 // and class layouts.  It happens to also be a fast cache for the HotSpot
 746 // signature types.
 747 class TypeTuple : public Type {
 748   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
 749 
 750   const uint          _cnt;              // Count of fields
 751   const Type ** const _fields;           // Array of field types
 752 
 753 public:
 754   virtual bool eq( const Type *t ) const;
 755   virtual uint hash() const;             // Type specific hashing
 756   virtual bool singleton(void) const;    // TRUE if type is a singleton
 757   virtual bool empty(void) const;        // TRUE if type is vacuous
 758 
 759   // Accessors:
 760   uint cnt() const { return _cnt; }
 761   const Type* field_at(uint i) const {
 762     assert(i < _cnt, "oob");
 763     return _fields[i];
 764   }
 765   void set_field_at(uint i, const Type* t) {
 766     assert(i < _cnt, "oob");
 767     _fields[i] = t;
 768   }
 769 
 770   static const TypeTuple *make( uint cnt, const Type **fields );
 771   static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces);
 772   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling);
 773 
 774   // Subroutine call type with space allocated for argument types
 775   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 776   static const Type **fields( uint arg_cnt );
 777 
 778   virtual const Type *xmeet( const Type *t ) const;
 779   virtual const Type *xdual() const;    // Compute dual right now.
 780   // Convenience common pre-built types.
 781   static const TypeTuple *IFBOTH;
 782   static const TypeTuple *IFFALSE;
 783   static const TypeTuple *IFTRUE;
 784   static const TypeTuple *IFNEITHER;
 785   static const TypeTuple *LOOPBODY;
 786   static const TypeTuple *MEMBAR;
 787   static const TypeTuple *STORECONDITIONAL;
 788   static const TypeTuple *START_I2C;
 789   static const TypeTuple *INT_PAIR;
 790   static const TypeTuple *LONG_PAIR;
 791   static const TypeTuple *INT_CC_PAIR;
 792   static const TypeTuple *LONG_CC_PAIR;
 793 #ifndef PRODUCT
 794   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 795 #endif
 796 };
 797 
 798 //------------------------------TypeAry----------------------------------------
 799 // Class of Array Types
 800 class TypeAry : public Type {
 801   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
 802       _elem(elem), _size(size), _stable(stable) {}
 803 public:
 804   virtual bool eq( const Type *t ) const;
 805   virtual uint hash() const;             // Type specific hashing
 806   virtual bool singleton(void) const;    // TRUE if type is a singleton
 807   virtual bool empty(void) const;        // TRUE if type is vacuous
 808 
 809 private:
 810   const Type *_elem;            // Element type of array
 811   const TypeInt *_size;         // Elements in array
 812   const bool _stable;           // Are elements @Stable?
 813   friend class TypeAryPtr;
 814 
 815 public:
 816   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
 817 
 818   virtual const Type *xmeet( const Type *t ) const;
 819   virtual const Type *xdual() const;    // Compute dual right now.
 820   bool ary_must_be_exact() const;  // true if arrays of such are never generic
 821   virtual const TypeAry* remove_speculative() const;
 822   virtual const Type* cleanup_speculative() const;
 823 #ifndef PRODUCT
 824   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 825 #endif
 826 };
 827 
 828 //------------------------------TypeVect---------------------------------------
 829 // Class of Vector Types
 830 class TypeVect : public Type {
 831   const BasicType _elem_bt;  // Vector's element type
 832   const uint _length;  // Elements in vector (power of 2)
 833 
 834 protected:
 835   TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
 836     _elem_bt(elem_bt), _length(length) {}
 837 
 838 public:
 839   BasicType element_basic_type() const { return _elem_bt; }
 840   uint length() const { return _length; }
 841   uint length_in_bytes() const {
 842     return _length * type2aelembytes(element_basic_type());
 843   }
 844 
 845   virtual bool eq(const Type* t) const;
 846   virtual uint hash() const;             // Type specific hashing
 847   virtual bool singleton(void) const;    // TRUE if type is a singleton
 848   virtual bool empty(void) const;        // TRUE if type is vacuous
 849 
 850   static const TypeVect* make(const BasicType elem_bt, uint length, bool is_mask = false);
 851   static const TypeVect* makemask(const BasicType elem_bt, uint length);
 852 
 853   virtual const Type* xmeet( const Type *t) const;
 854   virtual const Type* xdual() const;     // Compute dual right now.
 855 
 856   static const TypeVect* VECTA;
 857   static const TypeVect* VECTS;
 858   static const TypeVect* VECTD;
 859   static const TypeVect* VECTX;
 860   static const TypeVect* VECTY;
 861   static const TypeVect* VECTZ;
 862   static const TypeVect* VECTMASK;
 863 
 864 #ifndef PRODUCT
 865   virtual void dump2(Dict& d, uint, outputStream* st) const; // Specialized per-Type dumping
 866 #endif
 867 };
 868 
 869 class TypeVectA : public TypeVect {
 870   friend class TypeVect;
 871   TypeVectA(BasicType elem_bt, uint length) : TypeVect(VectorA, elem_bt, length) {}
 872 };
 873 
 874 class TypeVectS : public TypeVect {
 875   friend class TypeVect;
 876   TypeVectS(BasicType elem_bt, uint length) : TypeVect(VectorS, elem_bt, length) {}
 877 };
 878 
 879 class TypeVectD : public TypeVect {
 880   friend class TypeVect;
 881   TypeVectD(BasicType elem_bt, uint length) : TypeVect(VectorD, elem_bt, length) {}
 882 };
 883 
 884 class TypeVectX : public TypeVect {
 885   friend class TypeVect;
 886   TypeVectX(BasicType elem_bt, uint length) : TypeVect(VectorX, elem_bt, length) {}
 887 };
 888 
 889 class TypeVectY : public TypeVect {
 890   friend class TypeVect;
 891   TypeVectY(BasicType elem_bt, uint length) : TypeVect(VectorY, elem_bt, length) {}
 892 };
 893 
 894 class TypeVectZ : public TypeVect {
 895   friend class TypeVect;
 896   TypeVectZ(BasicType elem_bt, uint length) : TypeVect(VectorZ, elem_bt, length) {}
 897 };
 898 
 899 class TypeVectMask : public TypeVect {
 900 public:
 901   friend class TypeVect;
 902   TypeVectMask(BasicType elem_bt, uint length) : TypeVect(VectorMask, elem_bt, length) {}
 903   static const TypeVectMask* make(const BasicType elem_bt, uint length);
 904 };
 905 
 906 // Set of implemented interfaces. Referenced from TypeOopPtr and TypeKlassPtr.
 907 class TypeInterfaces : public Type {
 908 private:
 909   GrowableArrayFromArray<ciInstanceKlass*> _interfaces;
 910   uint _hash;
 911   ciInstanceKlass* _exact_klass;
 912   DEBUG_ONLY(bool _initialized;)
 913 
 914   void initialize();
 915 
 916   void verify() const NOT_DEBUG_RETURN;
 917   void compute_hash();
 918   void compute_exact_klass();
 919 
 920   TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces);
 921 
 922   NONCOPYABLE(TypeInterfaces);
 923 public:
 924   static const TypeInterfaces* make(GrowableArray<ciInstanceKlass*>* interfaces = nullptr);
 925   bool eq(const Type* other) const;
 926   bool eq(ciInstanceKlass* k) const;
 927   uint hash() const;
 928   const Type *xdual() const;
 929   void dump(outputStream* st) const;
 930   const TypeInterfaces* union_with(const TypeInterfaces* other) const;
 931   const TypeInterfaces* intersection_with(const TypeInterfaces* other) const;
 932   bool contains(const TypeInterfaces* other) const {
 933     return intersection_with(other)->eq(other);
 934   }
 935   bool empty() const { return _interfaces.length() == 0; }
 936 
 937   ciInstanceKlass* exact_klass() const;
 938   void verify_is_loaded() const NOT_DEBUG_RETURN;
 939 
 940   static int compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2);
 941   static int compare(ciInstanceKlass** k1, ciInstanceKlass** k2);
 942 
 943   const Type* xmeet(const Type* t) const;
 944 
 945   bool singleton(void) const;
 946   bool has_non_array_interface() const;
 947 };
 948 
 949 //------------------------------TypePtr----------------------------------------
 950 // Class of machine Pointer Types: raw data, instances or arrays.
 951 // If the _base enum is AnyPtr, then this refers to all of the above.
 952 // Otherwise the _base will indicate which subset of pointers is affected,
 953 // and the class will be inherited from.
 954 class TypePtr : public Type {
 955   friend class TypeNarrowPtr;
 956   friend class Type;
 957 protected:
 958   static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
 959 
 960 public:
 961   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
 962 protected:
 963   TypePtr(TYPES t, PTR ptr, int offset,
 964           const TypePtr* speculative = nullptr,
 965           int inline_depth = InlineDepthBottom) :
 966     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
 967     _ptr(ptr) {}
 968   static const PTR ptr_meet[lastPTR][lastPTR];
 969   static const PTR ptr_dual[lastPTR];
 970   static const char * const ptr_msg[lastPTR];
 971 
 972   enum {
 973     InlineDepthBottom = INT_MAX,
 974     InlineDepthTop = -InlineDepthBottom
 975   };
 976 
 977   // Extra type information profiling gave us. We propagate it the
 978   // same way the rest of the type info is propagated. If we want to
 979   // use it, then we have to emit a guard: this part of the type is
 980   // not something we know but something we speculate about the type.
 981   const TypePtr*   _speculative;
 982   // For speculative types, we record at what inlining depth the
 983   // profiling point that provided the data is. We want to favor
 984   // profile data coming from outer scopes which are likely better for
 985   // the current compilation.
 986   int _inline_depth;
 987 
 988   // utility methods to work on the speculative part of the type
 989   const TypePtr* dual_speculative() const;
 990   const TypePtr* xmeet_speculative(const TypePtr* other) const;
 991   bool eq_speculative(const TypePtr* other) const;
 992   int hash_speculative() const;
 993   const TypePtr* add_offset_speculative(intptr_t offset) const;
 994   const TypePtr* with_offset_speculative(intptr_t offset) const;
 995 #ifndef PRODUCT
 996   void dump_speculative(outputStream *st) const;
 997 #endif
 998 
 999   // utility methods to work on the inline depth of the type
1000   int dual_inline_depth() const;
1001   int meet_inline_depth(int depth) const;
1002 #ifndef PRODUCT
1003   void dump_inline_depth(outputStream *st) const;
1004 #endif
1005 
1006   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1007   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1008   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1009   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1010   // encountered so the right logic specific to klasses or oops can be executed.,
1011   enum MeetResult {
1012     QUICK,
1013     UNLOADED,
1014     SUBTYPE,
1015     NOT_SUBTYPE,
1016     LCA
1017   };
1018   template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1019                                                             const T* other_type, ciKlass*& res_klass, bool& res_xk);
1020 
1021   template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1022                                                   ciKlass*& res_klass, bool& res_xk);
1023 
1024   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);
1025   template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1026   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);
1027   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);
1028   template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1029   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);
1030   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);
1031   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);
1032 public:
1033   const int _offset;            // Offset into oop, with TOP & BOT
1034   const PTR _ptr;               // Pointer equivalence class
1035 
1036   int offset() const { return _offset; }
1037   PTR ptr()    const { return _ptr; }
1038 
1039   static const TypePtr *make(TYPES t, PTR ptr, int offset,
1040                              const TypePtr* speculative = nullptr,
1041                              int inline_depth = InlineDepthBottom);
1042 
1043   // Return a 'ptr' version of this type
1044   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1045 
1046   virtual intptr_t get_con() const;
1047 
1048   int xadd_offset( intptr_t offset ) const;
1049   virtual const TypePtr* add_offset(intptr_t offset) const;
1050   virtual const TypePtr* with_offset(intptr_t offset) const;
1051   virtual bool eq(const Type *t) const;
1052   virtual uint hash() const;             // Type specific hashing
1053 
1054   virtual bool singleton(void) const;    // TRUE if type is a singleton
1055   virtual bool empty(void) const;        // TRUE if type is vacuous
1056   virtual const Type *xmeet( const Type *t ) const;
1057   virtual const Type *xmeet_helper( const Type *t ) const;
1058   int meet_offset( int offset ) const;
1059   int dual_offset( ) const;
1060   virtual const Type *xdual() const;    // Compute dual right now.
1061 
1062   // meet, dual and join over pointer equivalence sets
1063   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1064   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1065 
1066   // This is textually confusing unless one recalls that
1067   // join(t) == dual()->meet(t->dual())->dual().
1068   PTR join_ptr( const PTR in_ptr ) const {
1069     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1070   }
1071 
1072   // Speculative type helper methods.
1073   virtual const TypePtr* speculative() const { return _speculative; }
1074   int inline_depth() const                   { return _inline_depth; }
1075   virtual ciKlass* speculative_type() const;
1076   virtual ciKlass* speculative_type_not_null() const;
1077   virtual bool speculative_maybe_null() const;
1078   virtual bool speculative_always_null() const;
1079   virtual const TypePtr* remove_speculative() const;
1080   virtual const Type* cleanup_speculative() const;
1081   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1082   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1083   virtual const TypePtr* with_inline_depth(int depth) const;
1084 
1085   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1086 
1087   // Tests for relation to centerline of type lattice:
1088   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1089   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1090   // Convenience common pre-built types.
1091   static const TypePtr *NULL_PTR;
1092   static const TypePtr *NOTNULL;
1093   static const TypePtr *BOTTOM;
1094 #ifndef PRODUCT
1095   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1096 #endif
1097 };
1098 
1099 //------------------------------TypeRawPtr-------------------------------------
1100 // Class of raw pointers, pointers to things other than Oops.  Examples
1101 // include the stack pointer, top of heap, card-marking area, handles, etc.
1102 class TypeRawPtr : public TypePtr {
1103 protected:
1104   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1105 public:
1106   virtual bool eq( const Type *t ) const;
1107   virtual uint hash() const;    // Type specific hashing
1108 
1109   const address _bits;          // Constant value, if applicable
1110 
1111   static const TypeRawPtr *make( PTR ptr );
1112   static const TypeRawPtr *make( address bits );
1113 
1114   // Return a 'ptr' version of this type
1115   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1116 
1117   virtual intptr_t get_con() const;
1118 
1119   virtual const TypePtr* add_offset(intptr_t offset) const;
1120   virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1121 
1122   virtual const Type *xmeet( const Type *t ) const;
1123   virtual const Type *xdual() const;    // Compute dual right now.
1124   // Convenience common pre-built types.
1125   static const TypeRawPtr *BOTTOM;
1126   static const TypeRawPtr *NOTNULL;
1127 #ifndef PRODUCT
1128   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1129 #endif
1130 };
1131 
1132 //------------------------------TypeOopPtr-------------------------------------
1133 // Some kind of oop (Java pointer), either instance or array.
1134 class TypeOopPtr : public TypePtr {
1135   friend class TypeAry;
1136   friend class TypePtr;
1137   friend class TypeInstPtr;
1138   friend class TypeAryPtr;
1139 protected:
1140  TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1141             const TypePtr* speculative, int inline_depth);
1142 public:
1143   virtual bool eq( const Type *t ) const;
1144   virtual uint hash() const;             // Type specific hashing
1145   virtual bool singleton(void) const;    // TRUE if type is a singleton
1146   enum {
1147    InstanceTop = -1,   // undefined instance
1148    InstanceBot = 0     // any possible instance
1149   };
1150 protected:
1151 
1152   // Oop is null, unless this is a constant oop.
1153   ciObject*     _const_oop;   // Constant oop
1154   // If _klass is null, then so is _sig.  This is an unloaded klass.
1155   ciKlass*      _klass;       // Klass object
1156 
1157   const TypeInterfaces* _interfaces;
1158 
1159   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1160   bool          _klass_is_exact;
1161   bool          _is_ptr_to_narrowoop;
1162   bool          _is_ptr_to_narrowklass;
1163   bool          _is_ptr_to_boxed_value;
1164 
1165   // If not InstanceTop or InstanceBot, indicates that this is
1166   // a particular instance of this type which is distinct.
1167   // This is the node index of the allocation node creating this instance.
1168   int           _instance_id;
1169 
1170   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1171 
1172   int dual_instance_id() const;
1173   int meet_instance_id(int uid) const;
1174 
1175   const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1176 
1177   // Do not allow interface-vs.-noninterface joins to collapse to top.
1178   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1179 
1180   virtual ciKlass* exact_klass_helper() const { return nullptr; }
1181   virtual ciKlass* klass() const { return _klass;     }
1182 
1183 public:
1184 
1185   bool is_java_subtype_of(const TypeOopPtr* other) const {
1186     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1187   }
1188 
1189   bool is_same_java_type_as(const TypePtr* other) const {
1190     return is_same_java_type_as_helper(other->is_oopptr());
1191   }
1192 
1193   virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1194     ShouldNotReachHere(); return false;
1195   }
1196 
1197   bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1198     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1199   }
1200   virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1201   virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1202 
1203 
1204   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1205   // Respects UseUniqueSubclasses.
1206   // If the klass is final, the resulting type will be exact.
1207   static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1208     return make_from_klass_common(klass, true, false, interface_handling);
1209   }
1210   // Same as before, but will produce an exact type, even if
1211   // the klass is not final, as long as it has exactly one implementation.
1212   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1213     return make_from_klass_common(klass, true, true, interface_handling);
1214   }
1215   // Same as before, but does not respects UseUniqueSubclasses.
1216   // Use this only for creating array element types.
1217   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1218     return make_from_klass_common(klass, false, false, interface_handling);
1219   }
1220   // Creates a singleton type given an object.
1221   // If the object cannot be rendered as a constant,
1222   // may return a non-singleton type.
1223   // If require_constant, produce a null if a singleton is not possible.
1224   static const TypeOopPtr* make_from_constant(ciObject* o,
1225                                               bool require_constant = false);
1226 
1227   // Make a generic (unclassed) pointer to an oop.
1228   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1229                                 const TypePtr* speculative = nullptr,
1230                                 int inline_depth = InlineDepthBottom);
1231 
1232   ciObject* const_oop()    const { return _const_oop; }
1233   // Exact klass, possibly an interface or an array of interface
1234   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1235   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1236 
1237   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1238   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1239 
1240   // Returns true if this pointer points at memory which contains a
1241   // compressed oop references.
1242   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1243   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1244   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1245   bool is_known_instance()       const { return _instance_id > 0; }
1246   int  instance_id()             const { return _instance_id; }
1247   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
1248 
1249   virtual intptr_t get_con() const;
1250 
1251   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1252 
1253   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1254 
1255   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1256 
1257   // corresponding pointer to klass, for a given instance
1258   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1259 
1260   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1261   virtual const TypePtr* add_offset(intptr_t offset) const;
1262 
1263   // Speculative type helper methods.
1264   virtual const TypeOopPtr* remove_speculative() const;
1265   virtual const Type* cleanup_speculative() const;
1266   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1267   virtual const TypePtr* with_inline_depth(int depth) const;
1268 
1269   virtual const TypePtr* with_instance_id(int instance_id) const;
1270 
1271   virtual const Type *xdual() const;    // Compute dual right now.
1272   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1273   virtual const Type *xmeet_helper(const Type *t) const;
1274 
1275   // Convenience common pre-built type.
1276   static const TypeOopPtr *BOTTOM;
1277 #ifndef PRODUCT
1278   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1279 #endif
1280 private:
1281   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1282     return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact());
1283   }
1284 
1285   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const {
1286     ShouldNotReachHere(); return false;
1287   }
1288 
1289   virtual const TypeInterfaces* interfaces() const {
1290     return _interfaces;
1291   };
1292 
1293   const TypeOopPtr* is_reference_type(const Type* other) const {
1294     return other->isa_oopptr();
1295   }
1296 
1297   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1298     return other->isa_aryptr();
1299   }
1300 
1301   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1302     return other->isa_instptr();
1303   }
1304 };
1305 
1306 //------------------------------TypeInstPtr------------------------------------
1307 // Class of Java object pointers, pointing either to non-array Java instances
1308 // or to a Klass* (including array klasses).
1309 class TypeInstPtr : public TypeOopPtr {
1310   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1311               const TypePtr* speculative, int inline_depth);
1312   virtual bool eq( const Type *t ) const;
1313   virtual uint hash() const;             // Type specific hashing
1314 
1315   ciKlass* exact_klass_helper() const;
1316 
1317 public:
1318 
1319   // Instance klass, ignoring any interface
1320   ciInstanceKlass* instance_klass() const {
1321     assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1322     return klass()->as_instance_klass();
1323   }
1324 
1325   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1326   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1327   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1328 
1329   // Make a pointer to a constant oop.
1330   static const TypeInstPtr *make(ciObject* o) {
1331     ciKlass* k = o->klass();
1332     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1333     return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1334   }
1335   // Make a pointer to a constant oop with offset.
1336   static const TypeInstPtr *make(ciObject* o, int offset) {
1337     ciKlass* k = o->klass();
1338     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1339     return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1340   }
1341 
1342   // Make a pointer to some value of type klass.
1343   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1344     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1345     return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1346   }
1347 
1348   // Make a pointer to some non-polymorphic value of exactly type klass.
1349   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1350     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1351     return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1352   }
1353 
1354   // Make a pointer to some value of type klass with offset.
1355   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1356     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1357     return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1358   }
1359 
1360   static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
1361                                  int instance_id = InstanceBot,
1362                                  const TypePtr* speculative = nullptr,
1363                                  int inline_depth = InlineDepthBottom);
1364 
1365   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {
1366     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1367     return make(ptr, k, interfaces, xk, o, offset, instance_id);
1368   }
1369 
1370   /** Create constant type for a constant boxed value */
1371   const Type* get_const_boxed_value() const;
1372 
1373   // If this is a java.lang.Class constant, return the type for it or null.
1374   // Pass to Type::get_const_type to turn it to a type, which will usually
1375   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1376   ciType* java_mirror_type() const;
1377 
1378   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1379 
1380   virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1381 
1382   virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1383 
1384   virtual const TypePtr* add_offset(intptr_t offset) const;
1385   virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1386 
1387   // Speculative type helper methods.
1388   virtual const TypeInstPtr* remove_speculative() const;
1389   const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1390   virtual const TypePtr* with_inline_depth(int depth) const;
1391   virtual const TypePtr* with_instance_id(int instance_id) const;
1392 
1393   // the core of the computation of the meet of 2 types
1394   virtual const Type *xmeet_helper(const Type *t) const;
1395   virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1396   virtual const Type *xdual() const;    // Compute dual right now.
1397 
1398   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1399 
1400   // Convenience common pre-built types.
1401   static const TypeInstPtr *NOTNULL;
1402   static const TypeInstPtr *BOTTOM;
1403   static const TypeInstPtr *MIRROR;
1404   static const TypeInstPtr *MARK;
1405   static const TypeInstPtr *KLASS;
1406 #ifndef PRODUCT
1407   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1408 #endif
1409 
1410 private:
1411   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1412 
1413   virtual bool is_meet_same_type_as(const TypePtr* other) const {
1414     return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1415   }
1416 
1417 };
1418 
1419 //------------------------------TypeAryPtr-------------------------------------
1420 // Class of Java array pointers
1421 class TypeAryPtr : public TypeOopPtr {
1422   friend class Type;
1423   friend class TypePtr;
1424   friend class TypeInterfaces;
1425 
1426   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1427               int offset, int instance_id, bool is_autobox_cache,
1428               const TypePtr* speculative, int inline_depth)
1429     : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1430     _ary(ary),
1431     _is_autobox_cache(is_autobox_cache)
1432  {
1433     int dummy;
1434     bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1435 
1436     if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1437         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1438         _offset != arrayOopDesc::klass_offset_in_bytes()) {
1439       _is_ptr_to_narrowoop = true;
1440     }
1441 
1442   }
1443   virtual bool eq( const Type *t ) const;
1444   virtual uint hash() const;    // Type specific hashing
1445   const TypeAry *_ary;          // Array we point into
1446   const bool     _is_autobox_cache;
1447 
1448   ciKlass* compute_klass() const;
1449 
1450   // A pointer to delay allocation to Type::Initialize_shared()
1451 
1452   static const TypeInterfaces* _array_interfaces;
1453   ciKlass* exact_klass_helper() const;
1454   // Only guaranteed non null for array of basic types
1455   ciKlass* klass() const;
1456 
1457 public:
1458 
1459   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1460   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1461   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1462 
1463   // returns base element type, an instance klass (and not interface) for object arrays
1464   const Type* base_element_type(int& dims) const;
1465 
1466   // Accessors
1467   bool  is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1468 
1469   const TypeAry* ary() const  { return _ary; }
1470   const Type*    elem() const { return _ary->_elem; }
1471   const TypeInt* size() const { return _ary->_size; }
1472   bool      is_stable() const { return _ary->_stable; }
1473 
1474   bool is_autobox_cache() const { return _is_autobox_cache; }
1475 
1476   static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1477                                 int instance_id = InstanceBot,
1478                                 const TypePtr* speculative = nullptr,
1479                                 int inline_depth = InlineDepthBottom);
1480   // Constant pointer to array
1481   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1482                                 int instance_id = InstanceBot,
1483                                 const TypePtr* speculative = nullptr,
1484                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);
1485 
1486   // Return a 'ptr' version of this type
1487   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1488 
1489   virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1490 
1491   virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1492 
1493   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1494   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1495 
1496   virtual bool empty(void) const;        // TRUE if type is vacuous
1497   virtual const TypePtr *add_offset( intptr_t offset ) const;
1498   virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1499   const TypeAryPtr* with_ary(const TypeAry* ary) const;
1500 
1501   // Speculative type helper methods.
1502   virtual const TypeAryPtr* remove_speculative() const;
1503   virtual const TypePtr* with_inline_depth(int depth) const;
1504   virtual const TypePtr* with_instance_id(int instance_id) const;
1505 
1506   // the core of the computation of the meet of 2 types
1507   virtual const Type *xmeet_helper(const Type *t) const;
1508   virtual const Type *xdual() const;    // Compute dual right now.
1509 
1510   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1511   int stable_dimension() const;
1512 
1513   const TypeAryPtr* cast_to_autobox_cache() const;
1514 
1515   static jint max_array_length(BasicType etype) ;
1516   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1517 
1518   // Convenience common pre-built types.
1519   static const TypeAryPtr* BOTTOM;
1520   static const TypeAryPtr* RANGE;
1521   static const TypeAryPtr* OOPS;
1522   static const TypeAryPtr* NARROWOOPS;
1523   static const TypeAryPtr* BYTES;
1524   static const TypeAryPtr* SHORTS;
1525   static const TypeAryPtr* CHARS;
1526   static const TypeAryPtr* INTS;
1527   static const TypeAryPtr* LONGS;
1528   static const TypeAryPtr* FLOATS;
1529   static const TypeAryPtr* DOUBLES;
1530   // selects one of the above:
1531   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1532     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1533     return _array_body_type[elem];
1534   }
1535   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1536   // sharpen the type of an int which is used as an array size
1537 #ifndef PRODUCT
1538   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1539 #endif
1540 private:
1541   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1542 };
1543 
1544 //------------------------------TypeMetadataPtr-------------------------------------
1545 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1546 class TypeMetadataPtr : public TypePtr {
1547 protected:
1548   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1549   // Do not allow interface-vs.-noninterface joins to collapse to top.
1550   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1551 public:
1552   virtual bool eq( const Type *t ) const;
1553   virtual uint hash() const;             // Type specific hashing
1554   virtual bool singleton(void) const;    // TRUE if type is a singleton
1555 
1556 private:
1557   ciMetadata*   _metadata;
1558 
1559 public:
1560   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1561 
1562   static const TypeMetadataPtr* make(ciMethod* m);
1563   static const TypeMetadataPtr* make(ciMethodData* m);
1564 
1565   ciMetadata* metadata() const { return _metadata; }
1566 
1567   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1568 
1569   virtual const TypePtr *add_offset( intptr_t offset ) const;
1570 
1571   virtual const Type *xmeet( const Type *t ) const;
1572   virtual const Type *xdual() const;    // Compute dual right now.
1573 
1574   virtual intptr_t get_con() const;
1575 
1576   // Convenience common pre-built types.
1577   static const TypeMetadataPtr *BOTTOM;
1578 
1579 #ifndef PRODUCT
1580   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1581 #endif
1582 };
1583 
1584 //------------------------------TypeKlassPtr-----------------------------------
1585 // Class of Java Klass pointers
1586 class TypeKlassPtr : public TypePtr {
1587   friend class TypeInstKlassPtr;
1588   friend class TypeAryKlassPtr;
1589   friend class TypePtr;
1590 protected:
1591   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset);
1592 
1593   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1594 
1595 public:
1596   virtual bool eq( const Type *t ) const;
1597   virtual uint hash() const;
1598   virtual bool singleton(void) const;    // TRUE if type is a singleton
1599 
1600 protected:
1601 
1602   ciKlass* _klass;
1603   const TypeInterfaces* _interfaces;
1604   const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1605   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1606   virtual ciKlass* exact_klass_helper() const;
1607   virtual ciKlass* klass() const { return  _klass; }
1608 
1609 public:
1610 
1611   bool is_java_subtype_of(const TypeKlassPtr* other) const {
1612     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1613   }
1614   bool is_same_java_type_as(const TypePtr* other) const {
1615     return is_same_java_type_as_helper(other->is_klassptr());
1616   }
1617 
1618   bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1619     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1620   }
1621   virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1622   virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1623   virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1624 
1625   // Exact klass, possibly an interface or an array of interface
1626   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1627   virtual bool klass_is_exact()    const { return _ptr == Constant; }
1628 
1629   static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1630   static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces);
1631 
1632   virtual bool  is_loaded() const { return _klass->is_loaded(); }
1633 
1634   virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1635 
1636   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1637 
1638   // corresponding pointer to instance, for a given class
1639   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1640 
1641   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1642   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1643   virtual const Type    *xdual() const { ShouldNotReachHere(); return nullptr; }
1644 
1645   virtual intptr_t get_con() const;
1646 
1647   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1648 
1649   virtual const TypeKlassPtr* try_improve() const { return this; }
1650 
1651 #ifndef PRODUCT
1652   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1653 #endif
1654 private:
1655   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1656     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1657   }
1658 
1659   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1660     ShouldNotReachHere(); return false;
1661   }
1662 
1663   virtual const TypeInterfaces* interfaces() const {
1664     return _interfaces;
1665   };
1666 
1667   const TypeKlassPtr* is_reference_type(const Type* other) const {
1668     return other->isa_klassptr();
1669   }
1670 
1671   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1672     return other->isa_aryklassptr();
1673   }
1674 
1675   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1676     return other->isa_instklassptr();
1677   }
1678 };
1679 
1680 // Instance klass pointer, mirrors TypeInstPtr
1681 class TypeInstKlassPtr : public TypeKlassPtr {
1682 
1683   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1684     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {
1685     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1686   }
1687 
1688   virtual bool must_be_exact() const;
1689 
1690 public:
1691   // Instance klass ignoring any interface
1692   ciInstanceKlass* instance_klass() const {
1693     assert(!klass()->is_interface(), "");
1694     return klass()->as_instance_klass();
1695   }
1696 
1697   bool might_be_an_array() const;
1698 
1699   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1700   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1701   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1702 
1703   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1704     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1705     return make(TypePtr::Constant, k, interfaces, 0);
1706   }
1707   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1708 
1709   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {
1710     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1711     return make(ptr, k, interfaces, offset);
1712   }
1713 
1714   virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1715 
1716   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1717 
1718   // corresponding pointer to instance, for a given class
1719   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1720   virtual uint hash() const;
1721   virtual bool eq(const Type *t) const;
1722 
1723   virtual const TypePtr *add_offset( intptr_t offset ) const;
1724   virtual const Type    *xmeet( const Type *t ) const;
1725   virtual const Type    *xdual() const;
1726   virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1727 
1728   virtual const TypeKlassPtr* try_improve() const;
1729 
1730   // Convenience common pre-built types.
1731   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1732   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1733 private:
1734   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1735 };
1736 
1737 // Array klass pointer, mirrors TypeAryPtr
1738 class TypeAryKlassPtr : public TypeKlassPtr {
1739   friend class TypeInstKlassPtr;
1740   friend class Type;
1741   friend class TypePtr;
1742 
1743   const Type *_elem;
1744 
1745   static const TypeInterfaces* _array_interfaces;
1746   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1747     : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1748     assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1749   }
1750 
1751   virtual ciKlass* exact_klass_helper() const;
1752   // Only guaranteed non null for array of basic types
1753   virtual ciKlass* klass() const;
1754 
1755   virtual bool must_be_exact() const;
1756 
1757 public:
1758 
1759   // returns base element type, an instance klass (and not interface) for object arrays
1760   const Type* base_element_type(int& dims) const;
1761 
1762   static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1763 
1764   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1765   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1766   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1767 
1768   bool  is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1769 
1770   static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1771   static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1772 
1773   const Type *elem() const { return _elem; }
1774 
1775   virtual bool eq(const Type *t) const;
1776   virtual uint hash() const;             // Type specific hashing
1777 
1778   virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
1779 
1780   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1781 
1782   // corresponding pointer to instance, for a given class
1783   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1784 
1785   virtual const TypePtr *add_offset( intptr_t offset ) const;
1786   virtual const Type    *xmeet( const Type *t ) const;
1787   virtual const Type    *xdual() const;      // Compute dual right now.
1788 
1789   virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
1790 
1791   virtual bool empty(void) const {
1792     return TypeKlassPtr::empty() || _elem->empty();
1793   }
1794 
1795 #ifndef PRODUCT
1796   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1797 #endif
1798 private:
1799   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1800 };
1801 
1802 class TypeNarrowPtr : public Type {
1803 protected:
1804   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1805 
1806   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1807                                                   _ptrtype(ptrtype) {
1808     assert(ptrtype->offset() == 0 ||
1809            ptrtype->offset() == OffsetBot ||
1810            ptrtype->offset() == OffsetTop, "no real offsets");
1811   }
1812 
1813   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1814   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1815   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1816   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1817   // Do not allow interface-vs.-noninterface joins to collapse to top.
1818   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1819 public:
1820   virtual bool eq( const Type *t ) const;
1821   virtual uint hash() const;             // Type specific hashing
1822   virtual bool singleton(void) const;    // TRUE if type is a singleton
1823 
1824   virtual const Type *xmeet( const Type *t ) const;
1825   virtual const Type *xdual() const;    // Compute dual right now.
1826 
1827   virtual intptr_t get_con() const;
1828 
1829   virtual bool empty(void) const;        // TRUE if type is vacuous
1830 
1831   // returns the equivalent ptr type for this compressed pointer
1832   const TypePtr *get_ptrtype() const {
1833     return _ptrtype;
1834   }
1835 
1836   bool is_known_instance() const {
1837     return _ptrtype->is_known_instance();
1838   }
1839 
1840 #ifndef PRODUCT
1841   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1842 #endif
1843 };
1844 
1845 //------------------------------TypeNarrowOop----------------------------------
1846 // A compressed reference to some kind of Oop.  This type wraps around
1847 // a preexisting TypeOopPtr and forwards most of it's operations to
1848 // the underlying type.  It's only real purpose is to track the
1849 // oopness of the compressed oop value when we expose the conversion
1850 // between the normal and the compressed form.
1851 class TypeNarrowOop : public TypeNarrowPtr {
1852 protected:
1853   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1854   }
1855 
1856   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1857     return t->isa_narrowoop();
1858   }
1859 
1860   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1861     return t->is_narrowoop();
1862   }
1863 
1864   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1865     return new TypeNarrowOop(t);
1866   }
1867 
1868   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1869     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1870   }
1871 
1872 public:
1873 
1874   static const TypeNarrowOop *make( const TypePtr* type);
1875 
1876   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1877     return make(TypeOopPtr::make_from_constant(con, require_constant));
1878   }
1879 
1880   static const TypeNarrowOop *BOTTOM;
1881   static const TypeNarrowOop *NULL_PTR;
1882 
1883   virtual const TypeNarrowOop* remove_speculative() const;
1884   virtual const Type* cleanup_speculative() const;
1885 
1886 #ifndef PRODUCT
1887   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1888 #endif
1889 };
1890 
1891 //------------------------------TypeNarrowKlass----------------------------------
1892 // A compressed reference to klass pointer.  This type wraps around a
1893 // preexisting TypeKlassPtr and forwards most of it's operations to
1894 // the underlying type.
1895 class TypeNarrowKlass : public TypeNarrowPtr {
1896 protected:
1897   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1898   }
1899 
1900   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1901     return t->isa_narrowklass();
1902   }
1903 
1904   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1905     return t->is_narrowklass();
1906   }
1907 
1908   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1909     return new TypeNarrowKlass(t);
1910   }
1911 
1912   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1913     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1914   }
1915 
1916 public:
1917   static const TypeNarrowKlass *make( const TypePtr* type);
1918 
1919   // static const TypeNarrowKlass *BOTTOM;
1920   static const TypeNarrowKlass *NULL_PTR;
1921 
1922 #ifndef PRODUCT
1923   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1924 #endif
1925 };
1926 
1927 //------------------------------TypeFunc---------------------------------------
1928 // Class of Array Types
1929 class TypeFunc : public Type {
1930   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}
1931   virtual bool eq( const Type *t ) const;
1932   virtual uint hash() const;             // Type specific hashing
1933   virtual bool singleton(void) const;    // TRUE if type is a singleton
1934   virtual bool empty(void) const;        // TRUE if type is vacuous
1935 
1936   const TypeTuple* const _domain;     // Domain of inputs
1937   const TypeTuple* const _range;      // Range of results
1938 
1939 public:
1940   // Constants are shared among ADLC and VM
1941   enum { Control    = AdlcVMDeps::Control,
1942          I_O        = AdlcVMDeps::I_O,
1943          Memory     = AdlcVMDeps::Memory,
1944          FramePtr   = AdlcVMDeps::FramePtr,
1945          ReturnAdr  = AdlcVMDeps::ReturnAdr,
1946          Parms      = AdlcVMDeps::Parms
1947   };
1948 
1949 
1950   // Accessors:
1951   const TypeTuple* domain() const { return _domain; }
1952   const TypeTuple* range()  const { return _range; }
1953 
1954   static const TypeFunc *make(ciMethod* method);
1955   static const TypeFunc *make(ciSignature signature, const Type* extra);
1956   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1957 
1958   virtual const Type *xmeet( const Type *t ) const;
1959   virtual const Type *xdual() const;    // Compute dual right now.
1960 
1961   BasicType return_type() const;
1962 
1963 #ifndef PRODUCT
1964   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1965 #endif
1966   // Convenience common pre-built types.
1967 };
1968 
1969 //------------------------------accessors--------------------------------------
1970 inline bool Type::is_ptr_to_narrowoop() const {
1971 #ifdef _LP64
1972   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
1973 #else
1974   return false;
1975 #endif
1976 }
1977 
1978 inline bool Type::is_ptr_to_narrowklass() const {
1979 #ifdef _LP64
1980   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
1981 #else
1982   return false;
1983 #endif
1984 }
1985 
1986 inline float Type::getf() const {
1987   assert( _base == FloatCon, "Not a FloatCon" );
1988   return ((TypeF*)this)->_f;
1989 }
1990 
1991 inline short Type::geth() const {
1992   assert(_base == HalfFloatCon, "Not a HalfFloatCon");
1993   return ((TypeH*)this)->_f;
1994 }
1995 
1996 inline double Type::getd() const {
1997   assert( _base == DoubleCon, "Not a DoubleCon" );
1998   return ((TypeD*)this)->_d;
1999 }
2000 
2001 inline const TypeInteger *Type::is_integer(BasicType bt) const {
2002   assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int");
2003   return (TypeInteger*)this;
2004 }
2005 
2006 inline const TypeInteger *Type::isa_integer(BasicType bt) const {
2007   return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : nullptr);
2008 }
2009 
2010 inline const TypeInt *Type::is_int() const {
2011   assert( _base == Int, "Not an Int" );
2012   return (TypeInt*)this;
2013 }
2014 
2015 inline const TypeInt *Type::isa_int() const {
2016   return ( _base == Int ? (TypeInt*)this : nullptr);
2017 }
2018 
2019 inline const TypeLong *Type::is_long() const {
2020   assert( _base == Long, "Not a Long" );
2021   return (TypeLong*)this;
2022 }
2023 
2024 inline const TypeLong *Type::isa_long() const {
2025   return ( _base == Long ? (TypeLong*)this : nullptr);
2026 }
2027 
2028 inline const TypeH* Type::isa_half_float() const {
2029   return ((_base == HalfFloatTop ||
2030            _base == HalfFloatCon ||
2031            _base == HalfFloatBot) ? (TypeH*)this : nullptr);
2032 }
2033 
2034 inline const TypeH* Type::is_half_float_constant() const {
2035   assert( _base == HalfFloatCon, "Not a HalfFloat" );
2036   return (TypeH*)this;
2037 }
2038 
2039 inline const TypeH* Type::isa_half_float_constant() const {
2040   return (_base == HalfFloatCon ? (TypeH*)this : nullptr);
2041 }
2042 
2043 inline const TypeF *Type::isa_float() const {
2044   return ((_base == FloatTop ||
2045            _base == FloatCon ||
2046            _base == FloatBot) ? (TypeF*)this : nullptr);
2047 }
2048 
2049 inline const TypeF *Type::is_float_constant() const {
2050   assert( _base == FloatCon, "Not a Float" );
2051   return (TypeF*)this;
2052 }
2053 
2054 inline const TypeF *Type::isa_float_constant() const {
2055   return ( _base == FloatCon ? (TypeF*)this : nullptr);
2056 }
2057 
2058 inline const TypeD *Type::isa_double() const {
2059   return ((_base == DoubleTop ||
2060            _base == DoubleCon ||
2061            _base == DoubleBot) ? (TypeD*)this : nullptr);
2062 }
2063 
2064 inline const TypeD *Type::is_double_constant() const {
2065   assert( _base == DoubleCon, "Not a Double" );
2066   return (TypeD*)this;
2067 }
2068 
2069 inline const TypeD *Type::isa_double_constant() const {
2070   return ( _base == DoubleCon ? (TypeD*)this : nullptr);
2071 }
2072 
2073 inline const TypeTuple *Type::is_tuple() const {
2074   assert( _base == Tuple, "Not a Tuple" );
2075   return (TypeTuple*)this;
2076 }
2077 
2078 inline const TypeAry *Type::is_ary() const {
2079   assert( _base == Array , "Not an Array" );
2080   return (TypeAry*)this;
2081 }
2082 
2083 inline const TypeAry *Type::isa_ary() const {
2084   return ((_base == Array) ? (TypeAry*)this : nullptr);
2085 }
2086 
2087 inline const TypeVectMask *Type::is_vectmask() const {
2088   assert( _base == VectorMask, "Not a Vector Mask" );
2089   return (TypeVectMask*)this;
2090 }
2091 
2092 inline const TypeVectMask *Type::isa_vectmask() const {
2093   return (_base == VectorMask) ? (TypeVectMask*)this : nullptr;
2094 }
2095 
2096 inline const TypeVect *Type::is_vect() const {
2097   assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" );
2098   return (TypeVect*)this;
2099 }
2100 
2101 inline const TypeVect *Type::isa_vect() const {
2102   return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : nullptr;
2103 }
2104 
2105 inline const TypePtr *Type::is_ptr() const {
2106   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2107   assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer");
2108   return (TypePtr*)this;
2109 }
2110 
2111 inline const TypePtr *Type::isa_ptr() const {
2112   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2113   return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : nullptr;
2114 }
2115 
2116 inline const TypeOopPtr *Type::is_oopptr() const {
2117   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2118   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
2119   return (TypeOopPtr*)this;
2120 }
2121 
2122 inline const TypeOopPtr *Type::isa_oopptr() const {
2123   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2124   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : nullptr;
2125 }
2126 
2127 inline const TypeRawPtr *Type::isa_rawptr() const {
2128   return (_base == RawPtr) ? (TypeRawPtr*)this : nullptr;
2129 }
2130 
2131 inline const TypeRawPtr *Type::is_rawptr() const {
2132   assert( _base == RawPtr, "Not a raw pointer" );
2133   return (TypeRawPtr*)this;
2134 }
2135 
2136 inline const TypeInstPtr *Type::isa_instptr() const {
2137   return (_base == InstPtr) ? (TypeInstPtr*)this : nullptr;
2138 }
2139 
2140 inline const TypeInstPtr *Type::is_instptr() const {
2141   assert( _base == InstPtr, "Not an object pointer" );
2142   return (TypeInstPtr*)this;
2143 }
2144 
2145 inline const TypeAryPtr *Type::isa_aryptr() const {
2146   return (_base == AryPtr) ? (TypeAryPtr*)this : nullptr;
2147 }
2148 
2149 inline const TypeAryPtr *Type::is_aryptr() const {
2150   assert( _base == AryPtr, "Not an array pointer" );
2151   return (TypeAryPtr*)this;
2152 }
2153 
2154 inline const TypeNarrowOop *Type::is_narrowoop() const {
2155   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2156   assert(_base == NarrowOop, "Not a narrow oop" ) ;
2157   return (TypeNarrowOop*)this;
2158 }
2159 
2160 inline const TypeNarrowOop *Type::isa_narrowoop() const {
2161   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2162   return (_base == NarrowOop) ? (TypeNarrowOop*)this : nullptr;
2163 }
2164 
2165 inline const TypeNarrowKlass *Type::is_narrowklass() const {
2166   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
2167   return (TypeNarrowKlass*)this;
2168 }
2169 
2170 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
2171   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : nullptr;
2172 }
2173 
2174 inline const TypeMetadataPtr *Type::is_metadataptr() const {
2175   // MetadataPtr is the first and CPCachePtr the last
2176   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
2177   return (TypeMetadataPtr*)this;
2178 }
2179 
2180 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
2181   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : nullptr;
2182 }
2183 
2184 inline const TypeKlassPtr *Type::isa_klassptr() const {
2185   return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : nullptr;
2186 }
2187 
2188 inline const TypeKlassPtr *Type::is_klassptr() const {
2189   assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer");
2190   return (TypeKlassPtr*)this;
2191 }
2192 
2193 inline const TypeInstKlassPtr *Type::isa_instklassptr() const {
2194   return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : nullptr;
2195 }
2196 
2197 inline const TypeInstKlassPtr *Type::is_instklassptr() const {
2198   assert(_base == InstKlassPtr, "Not a klass pointer");
2199   return (TypeInstKlassPtr*)this;
2200 }
2201 
2202 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const {
2203   return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : nullptr;
2204 }
2205 
2206 inline const TypeAryKlassPtr *Type::is_aryklassptr() const {
2207   assert(_base == AryKlassPtr, "Not a klass pointer");
2208   return (TypeAryKlassPtr*)this;
2209 }
2210 
2211 inline const TypePtr* Type::make_ptr() const {
2212   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
2213                               ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
2214                                                        isa_ptr());
2215 }
2216 
2217 inline const TypeOopPtr* Type::make_oopptr() const {
2218   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
2219 }
2220 
2221 inline const TypeNarrowOop* Type::make_narrowoop() const {
2222   return (_base == NarrowOop) ? is_narrowoop() :
2223                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2224 }
2225 
2226 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2227   return (_base == NarrowKlass) ? is_narrowklass() :
2228                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2229 }
2230 
2231 inline bool Type::is_floatingpoint() const {
2232   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2233       (_base == FloatCon)  || (_base == FloatBot) ||
2234       (_base == DoubleCon) || (_base == DoubleBot) )
2235     return true;
2236   return false;
2237 }
2238 
2239 template <>
2240 inline const TypeInt* Type::cast<TypeInt>() const {
2241   return is_int();
2242 }
2243 
2244 template <>
2245 inline const TypeLong* Type::cast<TypeLong>() const {
2246   return is_long();
2247 }
2248 
2249 // ===============================================================
2250 // Things that need to be 64-bits in the 64-bit build but
2251 // 32-bits in the 32-bit build.  Done this way to get full
2252 // optimization AND strong typing.
2253 #ifdef _LP64
2254 
2255 // For type queries and asserts
2256 #define is_intptr_t  is_long
2257 #define isa_intptr_t isa_long
2258 #define find_intptr_t_type find_long_type
2259 #define find_intptr_t_con  find_long_con
2260 #define TypeX        TypeLong
2261 #define Type_X       Type::Long
2262 #define TypeX_X      TypeLong::LONG
2263 #define TypeX_ZERO   TypeLong::ZERO
2264 // For 'ideal_reg' machine registers
2265 #define Op_RegX      Op_RegL
2266 // For phase->intcon variants
2267 #define MakeConX     longcon
2268 #define ConXNode     ConLNode
2269 // For array index arithmetic
2270 #define MulXNode     MulLNode
2271 #define AndXNode     AndLNode
2272 #define OrXNode      OrLNode
2273 #define CmpXNode     CmpLNode
2274 #define SubXNode     SubLNode
2275 #define LShiftXNode  LShiftLNode
2276 // For object size computation:
2277 #define AddXNode     AddLNode
2278 #define RShiftXNode  RShiftLNode
2279 // For card marks and hashcodes
2280 #define URShiftXNode URShiftLNode
2281 // For shenandoahSupport
2282 #define LoadXNode    LoadLNode
2283 #define StoreXNode   StoreLNode
2284 // Opcodes
2285 #define Op_LShiftX   Op_LShiftL
2286 #define Op_AndX      Op_AndL
2287 #define Op_AddX      Op_AddL
2288 #define Op_SubX      Op_SubL
2289 #define Op_XorX      Op_XorL
2290 #define Op_URShiftX  Op_URShiftL
2291 #define Op_LoadX     Op_LoadL
2292 // conversions
2293 #define ConvI2X(x)   ConvI2L(x)
2294 #define ConvL2X(x)   (x)
2295 #define ConvX2I(x)   ConvL2I(x)
2296 #define ConvX2L(x)   (x)
2297 #define ConvX2UL(x)  (x)
2298 
2299 #else
2300 
2301 // For type queries and asserts
2302 #define is_intptr_t  is_int
2303 #define isa_intptr_t isa_int
2304 #define find_intptr_t_type find_int_type
2305 #define find_intptr_t_con  find_int_con
2306 #define TypeX        TypeInt
2307 #define Type_X       Type::Int
2308 #define TypeX_X      TypeInt::INT
2309 #define TypeX_ZERO   TypeInt::ZERO
2310 // For 'ideal_reg' machine registers
2311 #define Op_RegX      Op_RegI
2312 // For phase->intcon variants
2313 #define MakeConX     intcon
2314 #define ConXNode     ConINode
2315 // For array index arithmetic
2316 #define MulXNode     MulINode
2317 #define AndXNode     AndINode
2318 #define OrXNode      OrINode
2319 #define CmpXNode     CmpINode
2320 #define SubXNode     SubINode
2321 #define LShiftXNode  LShiftINode
2322 // For object size computation:
2323 #define AddXNode     AddINode
2324 #define RShiftXNode  RShiftINode
2325 // For card marks and hashcodes
2326 #define URShiftXNode URShiftINode
2327 // For shenandoahSupport
2328 #define LoadXNode    LoadINode
2329 #define StoreXNode   StoreINode
2330 // Opcodes
2331 #define Op_LShiftX   Op_LShiftI
2332 #define Op_AndX      Op_AndI
2333 #define Op_AddX      Op_AddI
2334 #define Op_SubX      Op_SubI
2335 #define Op_XorX      Op_XorI
2336 #define Op_URShiftX  Op_URShiftI
2337 #define Op_LoadX     Op_LoadI
2338 // conversions
2339 #define ConvI2X(x)   (x)
2340 #define ConvL2X(x)   ConvL2I(x)
2341 #define ConvX2I(x)   (x)
2342 #define ConvX2L(x)   ConvI2L(x)
2343 #define ConvX2UL(x)  ConvI2UL(x)
2344 
2345 #endif
2346 
2347 #endif // SHARE_OPTO_TYPE_HPP