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