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