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