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