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