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