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   inline void* operator new( size_t x ) throw() {
 204     Compile* compile = Compile::current();
 205     compile->set_type_last_size(x);
 206     return compile->type_arena()->AmallocWords(x);
 207   }
 208   inline void operator delete( void* ptr ) {
 209     Compile* compile = Compile::current();
 210     compile->type_arena()->Afree(ptr,compile->type_last_size());
 211   }
 212 
 213   // Initialize the type system for a particular compilation.
 214   static void Initialize(Compile* compile);
 215 
 216   // Initialize the types shared by all compilations.
 217   static void Initialize_shared(Compile* compile);
 218 
 219   TYPES base() const {
 220     assert(_base > Bad && _base < lastype, "sanity");
 221     return _base;
 222   }
 223 
 224   // Create a new hash-consd type
 225   static const Type *make(enum TYPES);
 226   // Test for equivalence of types
 227   static bool equals(const Type* t1, const Type* t2);
 228   // Test for higher or equal in lattice
 229   // Variant that drops the speculative part of the types
 230   bool higher_equal(const Type* t) const {
 231     return equals(meet(t), t->remove_speculative());
 232   }
 233   // Variant that keeps the speculative part of the types
 234   bool higher_equal_speculative(const Type* t) const {
 235     return equals(meet_speculative(t), t);
 236   }
 237 
 238   // MEET operation; lower in lattice.
 239   // Variant that drops the speculative part of the types
 240   const Type *meet(const Type *t) const {
 241     return meet_helper(t, false);
 242   }
 243   // Variant that keeps the speculative part of the types
 244   const Type *meet_speculative(const Type *t) const {
 245     return meet_helper(t, true)->cleanup_speculative();
 246   }
 247   // WIDEN: 'widens' for Ints and other range types
 248   virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
 249   // NARROW: complement for widen, used by pessimistic phases
 250   virtual const Type *narrow( const Type *old ) const { return this; }
 251 
 252   // DUAL operation: reflect around lattice centerline.  Used instead of
 253   // join to ensure my lattice is symmetric up and down.
 254   const Type *dual() const { return _dual; }
 255 
 256   // Compute meet dependent on base type
 257   virtual const Type *xmeet( const Type *t ) const;
 258   virtual const Type *xdual() const;    // Compute dual right now.
 259 
 260   // JOIN operation; higher in lattice.  Done by finding the dual of the
 261   // meet of the dual of the 2 inputs.
 262   // Variant that drops the speculative part of the types
 263   const Type *join(const Type *t) const {
 264     return join_helper(t, false);
 265   }
 266   // Variant that keeps the speculative part of the types
 267   const Type *join_speculative(const Type *t) const {
 268     return join_helper(t, true)->cleanup_speculative();
 269   }
 270 
 271   // Modified version of JOIN adapted to the needs Node::Value.
 272   // Normalizes all empty values to TOP.  Does not kill _widen bits.
 273   // Variant that drops the speculative part of the types
 274   const Type *filter(const Type *kills) const {
 275     return filter_helper(kills, false);
 276   }
 277   // Variant that keeps the speculative part of the types
 278   const Type *filter_speculative(const Type *kills) const {
 279     return filter_helper(kills, true)->cleanup_speculative();
 280   }
 281 
 282   // Returns true if this pointer points at memory which contains a
 283   // compressed oop references.
 284   bool is_ptr_to_narrowoop() const;
 285   bool is_ptr_to_narrowklass() const;
 286 
 287   // Convenience access
 288   short geth() const;
 289   virtual float getf() const;
 290   double getd() const;
 291 
 292   // This has the same semantics as std::dynamic_cast<TypeClass*>(this)
 293   template <typename TypeClass>
 294   const TypeClass* try_cast() const;
 295 
 296   const TypeInt    *is_int() const;
 297   const TypeInt    *isa_int() const;             // Returns null if not an Int
 298   const TypeInteger* is_integer(BasicType bt) const;
 299   const TypeInteger* isa_integer(BasicType bt) const;
 300   const TypeLong   *is_long() const;
 301   const TypeLong   *isa_long() const;            // Returns null if not a Long
 302   const TypeD      *isa_double() const;          // Returns null if not a Double{Top,Con,Bot}
 303   const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
 304   const TypeD      *isa_double_constant() const; // Returns null if not a DoubleCon
 305   const TypeH      *isa_half_float() const;          // Returns null if not a HalfFloat{Top,Con,Bot}
 306   const TypeH      *is_half_float_constant() const;  // Asserts it is a HalfFloatCon
 307   const TypeH      *isa_half_float_constant() const; // Returns null if not a HalfFloatCon
 308   const TypeF      *isa_float() const;           // Returns null if not a Float{Top,Con,Bot}
 309   const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
 310   const TypeF      *isa_float_constant() const;  // Returns null if not a FloatCon
 311   const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
 312   const TypeAry    *is_ary() const;              // Array, NOT array pointer
 313   const TypeAry    *isa_ary() const;             // Returns null of not ary
 314   const TypeVect   *is_vect() const;             // Vector
 315   const TypeVect   *isa_vect() const;            // Returns null if not a Vector
 316   const TypeVectMask *is_vectmask() const;       // Predicate/Mask Vector
 317   const TypeVectMask *isa_vectmask() const;      // Returns null if not a Vector Predicate/Mask
 318   const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
 319   const TypePtr    *isa_ptr() const;             // Returns null if not ptr type
 320   const TypeRawPtr *isa_rawptr() const;          // NOT Java oop
 321   const TypeRawPtr *is_rawptr() const;           // Asserts is rawptr
 322   const TypeNarrowOop  *is_narrowoop() const;    // Java-style GC'd pointer
 323   const TypeNarrowOop  *isa_narrowoop() const;   // Returns null if not oop ptr type
 324   const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
 325   const TypeNarrowKlass *isa_narrowklass() const;// Returns null if not oop ptr type
 326   const TypeOopPtr   *isa_oopptr() const;        // Returns null if not oop ptr type
 327   const TypeOopPtr   *is_oopptr() const;         // Java-style GC'd pointer
 328   const TypeInstPtr  *isa_instptr() const;       // Returns null if not InstPtr
 329   const TypeInstPtr  *is_instptr() const;        // Instance
 330   const TypeAryPtr   *isa_aryptr() const;        // Returns null if not AryPtr
 331   const TypeAryPtr   *is_aryptr() const;         // Array oop
 332 
 333   template <typename TypeClass>
 334   const TypeClass* cast() const;
 335 
 336   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns null if not oop ptr type
 337   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
 338   const TypeKlassPtr      *isa_klassptr() const;      // Returns null if not KlassPtr
 339   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
 340   const TypeInstKlassPtr  *isa_instklassptr() const;  // Returns null if not IntKlassPtr
 341   const TypeInstKlassPtr  *is_instklassptr() const;   // assert if not IntKlassPtr
 342   const TypeAryKlassPtr   *isa_aryklassptr() const;   // Returns null if not AryKlassPtr
 343   const TypeAryKlassPtr   *is_aryklassptr() const;    // assert if not AryKlassPtr
 344 
 345   virtual bool      is_finite() const;           // Has a finite value
 346   virtual bool      is_nan()    const;           // Is not a number (NaN)
 347 



 348   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
 349   const TypePtr* make_ptr() const;
 350 
 351   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
 352   // Asserts if the underlying type is not an oopptr or narrowoop.
 353   const TypeOopPtr* make_oopptr() const;
 354 
 355   // Returns this compressed pointer or the equivalent compressed version
 356   // of this pointer type.
 357   const TypeNarrowOop* make_narrowoop() const;
 358 
 359   // Returns this compressed klass pointer or the equivalent
 360   // compressed version of this pointer type.
 361   const TypeNarrowKlass* make_narrowklass() const;
 362 
 363   // Special test for register pressure heuristic
 364   bool is_floatingpoint() const;        // True if Float or Double base type
 365 
 366   // Do you have memory, directly or through a tuple?
 367   bool has_memory( ) const;
 368 
 369   // TRUE if type is a singleton
 370   virtual bool singleton(void) const;
 371 
 372   // TRUE if type is above the lattice centerline, and is therefore vacuous
 373   virtual bool empty(void) const;
 374 
 375   // Return a hash for this type.  The hash function is public so ConNode
 376   // (constants) can hash on their constant, which is represented by a Type.
 377   virtual uint hash() const;
 378 
 379   // Map ideal registers (machine types) to ideal types
 380   static const Type *mreg2type[];
 381 
 382   // Printing, statistics
 383 #ifndef PRODUCT
 384   void         dump_on(outputStream *st) const;
 385   void         dump() const {
 386     dump_on(tty);
 387   }
 388   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 389   static  void dump_stats();
 390   // Groups of types, for debugging and visualization only.
 391   enum class Category {
 392     Data,
 393     Memory,
 394     Mixed,   // Tuples with types of different categories.
 395     Control,
 396     Other,   // {Type::Top, Type::Abio, Type::Bottom}.
 397     Undef    // {Type::Bad, Type::lastype}, for completeness.
 398   };
 399   // Return the category of this type.
 400   Category category() const;
 401   // Check recursively in tuples.
 402   bool has_category(Category cat) const;
 403 
 404   static const char* str(const Type* t);
 405 #endif // !PRODUCT
 406   void typerr(const Type *t) const; // Mixing types error
 407 
 408   // Create basic type
 409   static const Type* get_const_basic_type(BasicType type) {
 410     assert((uint)type <= T_CONFLICT && _const_basic_type[type] != nullptr, "bad type");
 411     return _const_basic_type[type];
 412   }
 413 
 414   // For two instance arrays of same dimension, return the base element types.
 415   // Otherwise or if the arrays have different dimensions, return null.
 416   static void get_arrays_base_elements(const Type *a1, const Type *a2,
 417                                        const TypeInstPtr **e1, const TypeInstPtr **e2);
 418 
 419   // Mapping to the array element's basic type.
 420   BasicType array_element_basic_type() const;
 421 
 422   enum InterfaceHandling {
 423       trust_interfaces,
 424       ignore_interfaces
 425   };
 426   // Create standard type for a ciType:
 427   static const Type* get_const_type(ciType* type, InterfaceHandling interface_handling = ignore_interfaces);
 428 
 429   // Create standard zero value:
 430   static const Type* get_zero_type(BasicType type) {
 431     assert((uint)type <= T_CONFLICT && _zero_type[type] != nullptr, "bad type");
 432     return _zero_type[type];
 433   }
 434 
 435   // Report if this is a zero value (not top).
 436   bool is_zero_type() const {
 437     BasicType type = basic_type();
 438     if (type == T_VOID || type >= T_CONFLICT)
 439       return false;
 440     else
 441       return (this == _zero_type[type]);
 442   }
 443 
 444   // Convenience common pre-built types.
 445   static const Type *ABIO;
 446   static const Type *BOTTOM;
 447   static const Type *CONTROL;
 448   static const Type *DOUBLE;
 449   static const Type *FLOAT;
 450   static const Type *HALF_FLOAT;
 451   static const Type *HALF;
 452   static const Type *MEMORY;
 453   static const Type *MULTI;
 454   static const Type *RETURN_ADDRESS;
 455   static const Type *TOP;
 456 
 457   // Mapping from compiler type to VM BasicType
 458   BasicType basic_type() const       { return _type_info[_base].basic_type; }
 459   uint ideal_reg() const             { return _type_info[_base].ideal_reg; }
 460   const char* msg() const            { return _type_info[_base].msg; }
 461   bool isa_oop_ptr() const           { return _type_info[_base].isa_oop; }
 462   relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
 463 
 464   // Mapping from CI type system to compiler type:
 465   static const Type* get_typeflow_type(ciType* type);
 466 
 467   static const Type* make_from_constant(ciConstant constant,
 468                                         bool require_constant = false,
 469                                         int stable_dimension = 0,
 470                                         bool is_narrow = false,
 471                                         bool is_autobox_cache = false);
 472 
 473   static const Type* make_constant_from_field(ciInstance* holder,
 474                                               int off,
 475                                               bool is_unsigned_load,
 476                                               BasicType loadbt);
 477 
 478   static const Type* make_constant_from_field(ciField* field,
 479                                               ciInstance* holder,
 480                                               BasicType loadbt,
 481                                               bool is_unsigned_load);
 482 
 483   static const Type* make_constant_from_array_element(ciArray* array,
 484                                                       int off,
 485                                                       int stable_dimension,
 486                                                       BasicType loadbt,
 487                                                       bool is_unsigned_load);
 488 
 489   // Speculative type helper methods. See TypePtr.
 490   virtual const TypePtr* speculative() const                                  { return nullptr; }
 491   virtual ciKlass* speculative_type() const                                   { return nullptr; }
 492   virtual ciKlass* speculative_type_not_null() const                          { return nullptr; }
 493   virtual bool speculative_maybe_null() const                                 { return true; }
 494   virtual bool speculative_always_null() const                                { return true; }
 495   virtual const Type* remove_speculative() const                              { return this; }
 496   virtual const Type* cleanup_speculative() const                             { return this; }
 497   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != nullptr; }
 498   virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
 499   const Type* maybe_remove_speculative(bool include_speculative) const;
 500 
 501   virtual bool maybe_null() const { return true; }
 502   virtual bool is_known_instance() const { return false; }
 503 
 504 private:
 505   // support arrays
 506   static const Type*        _zero_type[T_CONFLICT+1];
 507   static const Type* _const_basic_type[T_CONFLICT+1];
 508 };
 509 
 510 //------------------------------TypeF------------------------------------------
 511 // Class of Float-Constant Types.
 512 class TypeF : public Type {
 513   TypeF( float f ) : Type(FloatCon), _f(f) {};
 514 public:
 515   virtual bool eq( const Type *t ) const;
 516   virtual uint hash() const;             // Type specific hashing
 517   virtual bool singleton(void) const;    // TRUE if type is a singleton
 518   virtual bool empty(void) const;        // TRUE if type is vacuous
 519 public:
 520   const float _f;               // Float constant
 521 
 522   static const TypeF *make(float f);
 523 
 524   virtual bool        is_finite() const;  // Has a finite value
 525   virtual bool        is_nan()    const;  // Is not a number (NaN)
 526 
 527   virtual const Type *xmeet( const Type *t ) const;
 528   virtual const Type *xdual() const;    // Compute dual right now.
 529   // Convenience common pre-built types.
 530   static const TypeF *MAX;
 531   static const TypeF *MIN;
 532   static const TypeF *ZERO; // positive zero only
 533   static const TypeF *ONE;
 534   static const TypeF *POS_INF;
 535   static const TypeF *NEG_INF;
 536 #ifndef PRODUCT
 537   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 538 #endif
 539 };
 540 
 541 // Class of Half Float-Constant Types.
 542 class TypeH : public Type {
 543   TypeH(short f) : Type(HalfFloatCon), _f(f) {};
 544 public:
 545   virtual bool eq(const Type* t) const;
 546   virtual uint hash() const;             // Type specific hashing
 547   virtual bool singleton(void) const;    // TRUE if type is a singleton
 548   virtual bool empty(void) const;        // TRUE if type is vacuous
 549 public:
 550   const short _f;                        // Half Float constant
 551 
 552   static const TypeH* make(float f);
 553   static const TypeH* make(short f);
 554 
 555   virtual bool is_finite() const;  // Has a finite value
 556   virtual bool is_nan() const;     // Is not a number (NaN)
 557 
 558   virtual float getf() const;
 559   virtual const Type* xmeet(const Type* t) const;
 560   virtual const Type* xdual() const;    // Compute dual right now.
 561   // Convenience common pre-built types.
 562   static const TypeH* MAX;
 563   static const TypeH* MIN;
 564   static const TypeH* ZERO; // positive zero only
 565   static const TypeH* ONE;
 566   static const TypeH* POS_INF;
 567   static const TypeH* NEG_INF;
 568 #ifndef PRODUCT
 569   virtual void dump2(Dict &d, uint depth, outputStream* st) const;
 570 #endif
 571 };
 572 
 573 //------------------------------TypeD------------------------------------------
 574 // Class of Double-Constant Types.
 575 class TypeD : public Type {
 576   TypeD( double d ) : Type(DoubleCon), _d(d) {};
 577 public:
 578   virtual bool eq( const Type *t ) const;
 579   virtual uint hash() const;             // Type specific hashing
 580   virtual bool singleton(void) const;    // TRUE if type is a singleton
 581   virtual bool empty(void) const;        // TRUE if type is vacuous
 582 public:
 583   const double _d;              // Double constant
 584 
 585   static const TypeD *make(double d);
 586 
 587   virtual bool        is_finite() const;  // Has a finite value
 588   virtual bool        is_nan()    const;  // Is not a number (NaN)
 589 
 590   virtual const Type *xmeet( const Type *t ) const;
 591   virtual const Type *xdual() const;    // Compute dual right now.
 592   // Convenience common pre-built types.
 593   static const TypeD *MAX;
 594   static const TypeD *MIN;
 595   static const TypeD *ZERO; // positive zero only
 596   static const TypeD *ONE;
 597   static const TypeD *POS_INF;
 598   static const TypeD *NEG_INF;
 599 #ifndef PRODUCT
 600   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 601 #endif
 602 };
 603 
 604 class TypeInteger : public Type {
 605 protected:
 606   TypeInteger(TYPES t, int w, bool dual) : Type(t), _is_dual(dual), _widen(w) {}
 607 
 608   // Denote that a set is a dual set.
 609   // Dual sets are only used to compute the join of 2 sets, and not used
 610   // outside.
 611   const bool _is_dual;
 612 
 613 public:
 614   const short _widen;           // Limit on times we widen this sucker
 615 
 616   virtual jlong hi_as_long() const = 0;
 617   virtual jlong lo_as_long() const = 0;
 618   jlong get_con_as_long(BasicType bt) const;
 619   bool is_con() const { return lo_as_long() == hi_as_long(); }
 620   virtual short widen_limit() const { return _widen; }
 621 
 622   static const TypeInteger* make(jlong lo, jlong hi, int w, BasicType bt);
 623   static const TypeInteger* make(jlong con, BasicType bt);
 624 
 625   static const TypeInteger* bottom(BasicType type);
 626   static const TypeInteger* zero(BasicType type);
 627   static const TypeInteger* one(BasicType type);
 628   static const TypeInteger* minus_1(BasicType type);
 629 };
 630 
 631 /**
 632  * Definition:
 633  *
 634  * A TypeInt represents a set of non-empty jint values. A jint v is an element
 635  * of a TypeInt iff:
 636  *
 637  *   v >= _lo && v <= _hi &&
 638  *   juint(v) >= _ulo && juint(v) <= _uhi &&
 639  *   _bits.is_satisfied_by(v)
 640  *
 641  * Multiple sets of parameters can represent the same set.
 642  * E.g: consider 2 TypeInt t1, t2
 643  *
 644  * t1._lo = 2, t1._hi = 7, t1._ulo = 0, t1._uhi = 5, t1._bits._zeros = 0x00000000, t1._bits._ones = 0x1
 645  * t2._lo = 3, t2._hi = 5, t2._ulo = 3, t2._uhi = 5, t2._bits._zeros = 0xFFFFFFF8, t2._bits._ones = 0x1
 646  *
 647  * Then, t1 and t2 both represent the set {3, 5}. We can also see that the
 648  * constraints of t2 are the tightest possible. I.e there exists no TypeInt t3
 649  * which also represents {3, 5} such that any of these would be true:
 650  *
 651  *  1)  t3._lo  > t2._lo
 652  *  2)  t3._hi  < t2._hi
 653  *  3)  t3._ulo > t2._ulo
 654  *  4)  t3._uhi < t2._uhi
 655  *  5)  (t3._bits._zeros &~ t2._bis._zeros) != 0
 656  *  6)  (t3._bits._ones  &~ t2._bits._ones) != 0
 657  *
 658  * The 5-th condition mean that the subtraction of the bitsets represented by
 659  * t3._bits._zeros and t2._bits._zeros is not empty, which means that the
 660  * bits in t3._bits._zeros is not a subset of those in t2._bits._zeros, the
 661  * same applies to _bits._ones
 662  *
 663  * To simplify reasoning about the types in optimizations, we canonicalize
 664  * every TypeInt to its tightest form, already at construction. E.g a TypeInt
 665  * t with t._lo < 0 will definitely contain negative values. It also makes it
 666  * trivial to determine if a TypeInt instance is a subset of another.
 667  *
 668  * Lemmas:
 669  *
 670  * 1. Since every TypeInt instance is non-empty and canonicalized, all the
 671  *   bounds must also be elements of such TypeInt. Or else, we can tighten the
 672  *   bounds by narrowing it by one, which contradicts the assumption of the
 673  *   TypeInt being canonical.
 674  *
 675  * 2.
 676  *   2.1.  _lo <= jint(_ulo)
 677  *   2.2.  _lo <= _hi
 678  *   2.3.  _lo <= jint(_uhi)
 679  *   2.4.  _ulo <= juint(_lo)
 680  *   2.5.  _ulo <= juint(_hi)
 681  *   2.6.  _ulo <= _uhi
 682  *   2.7.  _hi >= _lo
 683  *   2.8.  _hi >= jint(_ulo)
 684  *   2.9.  _hi >= jint(_uhi)
 685  *   2.10. _uhi >= juint(_lo)
 686  *   2.11. _uhi >= _ulo
 687  *   2.12. _uhi >= juint(_hi)
 688  *
 689  *   Proof of lemma 2:
 690  *
 691  *   2.1. _lo <= jint(_ulo):
 692  *     According the lemma 1, _ulo is an element of the TypeInt, so in the
 693  *     signed domain, it must not be less than the smallest element of that
 694  *     TypeInt, which is _lo. Which means that _lo <= _ulo in the signed
 695  *     domain, or in a more programmatical way, _lo <= jint(_ulo).
 696  *   2.2. _lo <= _hi:
 697  *     According the lemma 1, _hi is an element of the TypeInt, so in the
 698  *     signed domain, it must not be less than the smallest element of that
 699  *     TypeInt, which is _lo. Which means that _lo <= _hi.
 700  *
 701  *   The other inequalities can be proved in a similar manner.
 702  *
 703  * 3. Given 2 jint values x, y where either both >= 0 or both < 0. Then:
 704  *
 705  *   x <= y iff juint(x) <= juint(y)
 706  *   I.e. x <= y in the signed domain iff x <= y in the unsigned domain
 707  *
 708  * 4. Either _lo == jint(_ulo) and _hi == jint(_uhi), or each element of a
 709  *   TypeInt lies in either interval [_lo, jint(_uhi)] or [jint(_ulo), _hi]
 710  *   (note that these intervals are disjoint in this case).
 711  *
 712  *   Proof of lemma 4:
 713  *
 714  *   For a TypeInt t, there are 3 possible cases:
 715  *
 716  *   a. t._lo >= 0, we have:
 717  *
 718  *     0 <= t_lo <= jint(t._ulo)           (lemma 2.1)
 719  *     juint(t._lo) <= juint(jint(t._ulo)) (lemma 3)
 720  *                  == t._ulo              (juint(jint(v)) == v with juint v)
 721  *                  <= juint(t._lo)        (lemma 2.4)
 722  *
 723  *     Which means that t._lo == jint(t._ulo).
 724  *
 725  *     Furthermore,
 726  *
 727  *     0 <= t._lo <= t._hi                 (lemma 2.2)
 728  *     0 <= t._lo <= jint(t._uhi)          (lemma 2.3)
 729  *     t._hi >= jint(t._uhi)               (lemma 2.9)
 730  *
 731  *     juint(t._hi) >= juint(jint(t._uhi)) (lemma 3)
 732  *                  == t._uhi              (juint(jint(v)) == v with juint v)
 733  *                  >= juint(t._hi)        (lemma 2.12)
 734  *
 735  *     Which means that t._hi == jint(t._uhi).
 736  *     In this case, t._lo == jint(t._ulo) and t._hi == jint(t._uhi)
 737  *
 738  *   b. t._hi < 0. Similarly, we can conclude that:
 739  *     t._lo == jint(t._ulo) and t._hi == jint(t._uhi)
 740  *
 741  *   c. t._lo < 0, t._hi >= 0.
 742  *
 743  *     Since t._ulo <= juint(t._hi) (lemma 2.5), we must have jint(t._ulo) >= 0
 744  *     because all negative values is larger than all non-negative values in the
 745  *     unsigned domain.
 746  *
 747  *     Since t._uhi >= juint(t._lo) (lemma 2.10), we must have jint(t._uhi) < 0
 748  *     similar to the reasoning above.
 749  *
 750  *     In this case, each element of t belongs to either [t._lo, jint(t._uhi)] or
 751  *     [jint(t._ulo), t._hi].
 752  *
 753  *     Below is an illustration of the TypeInt in this case, the intervals that
 754  *     the elements can be in are marked using the = symbol. Note how the
 755  *     negative range in the signed domain wrap around in the unsigned domain.
 756  *
 757  *     Signed:
 758  *     -----lo=========uhi---------0--------ulo==========hi-----
 759  *     Unsigned:
 760  *                                 0--------ulo==========hi----------lo=========uhi---------
 761  *
 762  *   This property is useful for our analysis of TypeInt values. Additionally,
 763  *   it can be seen that _lo and jint(_uhi) are both < 0 or both >= 0, and the
 764  *   same applies to jint(_ulo) and _hi.
 765  *
 766  *   We call [_lo, jint(_uhi)] and [jint(_ulo), _hi] "simple intervals". Then,
 767  *   a TypeInt consists of 2 simple intervals, each of which has its bounds
 768  *   being both >= 0 or both < 0. If both simple intervals lie in the same half
 769  *   of the integer domain, they must be the same (i.e _lo == jint(_ulo) and
 770  *   _hi == jint(_uhi)). Otherwise, [_lo, jint(_uhi)] must lie in the negative
 771  *   half and [jint(_ulo), _hi] must lie in the non-negative half of the signed
 772  *   domain (equivalently, [_lo, jint(_uhi)] must lie in the upper half and
 773  *   [jint(_ulo), _hi] must lie in the lower half of the unsigned domain).
 774  */
 775 class TypeInt : public TypeInteger {
 776 private:
 777   TypeInt(const TypeIntPrototype<jint, juint>& t, int w, bool dual);
 778   static const Type* make_or_top(const TypeIntPrototype<jint, juint>& t, int widen, bool dual);
 779 
 780   friend class TypeIntHelper;
 781 
 782 protected:
 783   virtual const Type* filter_helper(const Type* kills, bool include_speculative) const;
 784 
 785 public:
 786   typedef jint NativeType;
 787   virtual bool eq(const Type* t) const;
 788   virtual uint hash() const;             // Type specific hashing
 789   virtual bool singleton(void) const;    // TRUE if type is a singleton
 790   virtual bool empty(void) const;        // TRUE if type is vacuous
 791   // A value is in the set represented by this TypeInt if it satisfies all
 792   // the below constraints, see contains(jint)
 793   const jint _lo, _hi;       // Lower bound, upper bound in the signed domain
 794   const juint _ulo, _uhi;    // Lower bound, upper bound in the unsigned domain
 795   const KnownBits<juint> _bits;
 796 
 797   static const TypeInt* make(jint con);
 798   // must always specify w
 799   static const TypeInt* make(jint lo, jint hi, int widen);
 800   static const Type* make_or_top(const TypeIntPrototype<jint, juint>& t, int widen);
 801   static const TypeInt* make(const TypeIntPrototype<jint, juint>& t, int widen) { return make_or_top(t, widen)->is_int(); }
 802 
 803   // Check for single integer
 804   bool is_con() const { return _lo == _hi; }
 805   bool is_con(jint i) const { return is_con() && _lo == i; }
 806   jint get_con() const { assert(is_con(), "");  return _lo; }
 807   // Check if a jint/TypeInt is a subset of this TypeInt (i.e. all elements of the
 808   // argument are also elements of this type)
 809   bool contains(jint i) const;
 810   bool contains(const TypeInt* t) const;
 811 
 812   virtual bool is_finite() const;  // Has a finite value
 813 
 814   virtual const Type* xmeet(const Type* t) const;
 815   virtual const Type* xdual() const;    // Compute dual right now.
 816   virtual const Type* widen(const Type* t, const Type* limit_type) const;
 817   virtual const Type* narrow(const Type* t) const;
 818 
 819   virtual jlong hi_as_long() const { return _hi; }
 820   virtual jlong lo_as_long() const { return _lo; }
 821 
 822   // Do not kill _widen bits.
 823   // Convenience common pre-built types.
 824   static const TypeInt* MAX;
 825   static const TypeInt* MIN;
 826   static const TypeInt* MINUS_1;
 827   static const TypeInt* ZERO;
 828   static const TypeInt* ONE;
 829   static const TypeInt* BOOL;
 830   static const TypeInt* CC;
 831   static const TypeInt* CC_LT;  // [-1]  == MINUS_1
 832   static const TypeInt* CC_GT;  // [1]   == ONE
 833   static const TypeInt* CC_EQ;  // [0]   == ZERO
 834   static const TypeInt* CC_NE;  // [-1, 1]
 835   static const TypeInt* CC_LE;  // [-1,0]
 836   static const TypeInt* CC_GE;  // [0,1] == BOOL (!)
 837   static const TypeInt* BYTE;
 838   static const TypeInt* UBYTE;
 839   static const TypeInt* CHAR;
 840   static const TypeInt* SHORT;
 841   static const TypeInt* NON_ZERO;
 842   static const TypeInt* POS;
 843   static const TypeInt* POS1;
 844   static const TypeInt* INT;
 845   static const TypeInt* SYMINT; // symmetric range [-max_jint..max_jint]
 846   static const TypeInt* TYPE_DOMAIN; // alias for TypeInt::INT
 847 
 848   static const TypeInt* as_self(const Type* t) { return t->is_int(); }
 849 #ifndef PRODUCT
 850   virtual void dump2(Dict& d, uint depth, outputStream* st) const;
 851   void dump_verbose() const;
 852 #endif
 853 };
 854 
 855 // Similar to TypeInt
 856 class TypeLong : public TypeInteger {
 857 private:
 858   TypeLong(const TypeIntPrototype<jlong, julong>& t, int w, bool dual);
 859   static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual);
 860 
 861   friend class TypeIntHelper;
 862 
 863 protected:
 864   // Do not kill _widen bits.
 865   virtual const Type* filter_helper(const Type* kills, bool include_speculative) const;
 866 public:
 867   typedef jlong NativeType;
 868   virtual bool eq( const Type *t ) const;
 869   virtual uint hash() const;             // Type specific hashing
 870   virtual bool singleton(void) const;    // TRUE if type is a singleton
 871   virtual bool empty(void) const;        // TRUE if type is vacuous
 872 public:
 873   // A value is in the set represented by this TypeLong if it satisfies all
 874   // the below constraints, see contains(jlong)
 875   const jlong _lo, _hi;       // Lower bound, upper bound in the signed domain
 876   const julong _ulo, _uhi;    // Lower bound, upper bound in the unsigned domain
 877   const KnownBits<julong> _bits;
 878 
 879   static const TypeLong* make(jlong con);
 880   // must always specify w
 881   static const TypeLong* make(jlong lo, jlong hi, int widen);
 882   static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen);
 883   static const TypeLong* make(const TypeIntPrototype<jlong, julong>& t, int widen) { return make_or_top(t, widen)->is_long(); }
 884 
 885   // Check for single integer
 886   bool is_con() const { return _lo == _hi; }
 887   bool is_con(jlong i) const { return is_con() && _lo == i; }
 888   jlong get_con() const { assert(is_con(), "" ); return _lo; }
 889   // Check if a jlong/TypeLong is a subset of this TypeLong (i.e. all elements of the
 890   // argument are also elements of this type)
 891   bool contains(jlong i) const;
 892   bool contains(const TypeLong* t) const;
 893 
 894   // Check for positive 32-bit value.
 895   int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
 896 
 897   virtual bool        is_finite() const;  // Has a finite value
 898 
 899   virtual jlong hi_as_long() const { return _hi; }
 900   virtual jlong lo_as_long() const { return _lo; }
 901 
 902   virtual const Type* xmeet(const Type* t) const;
 903   virtual const Type* xdual() const;    // Compute dual right now.
 904   virtual const Type* widen(const Type* t, const Type* limit_type) const;
 905   virtual const Type* narrow(const Type* t) const;
 906   // Convenience common pre-built types.
 907   static const TypeLong* MAX;
 908   static const TypeLong* MIN;
 909   static const TypeLong* MINUS_1;
 910   static const TypeLong* ZERO;
 911   static const TypeLong* ONE;
 912   static const TypeLong* NON_ZERO;
 913   static const TypeLong* POS;
 914   static const TypeLong* NEG;
 915   static const TypeLong* LONG;
 916   static const TypeLong* INT;    // 32-bit subrange [min_jint..max_jint]
 917   static const TypeLong* UINT;   // 32-bit unsigned [0..max_juint]
 918   static const TypeLong* TYPE_DOMAIN; // alias for TypeLong::LONG
 919 
 920   // static convenience methods.
 921   static const TypeLong* as_self(const Type* t) { return t->is_long(); }
 922 
 923 #ifndef PRODUCT
 924   virtual void dump2(Dict& d, uint, outputStream* st) const;// Specialized per-Type dumping
 925   void dump_verbose() const;
 926 #endif
 927 };
 928 
 929 //------------------------------TypeTuple--------------------------------------
 930 // Class of Tuple Types, essentially type collections for function signatures
 931 // and class layouts.  It happens to also be a fast cache for the HotSpot
 932 // signature types.
 933 class TypeTuple : public Type {
 934   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
 935 
 936   const uint          _cnt;              // Count of fields
 937   const Type ** const _fields;           // Array of field types
 938 
 939 public:
 940   virtual bool eq( const Type *t ) const;
 941   virtual uint hash() const;             // Type specific hashing
 942   virtual bool singleton(void) const;    // TRUE if type is a singleton
 943   virtual bool empty(void) const;        // TRUE if type is vacuous
 944 
 945   // Accessors:
 946   uint cnt() const { return _cnt; }
 947   const Type* field_at(uint i) const {
 948     assert(i < _cnt, "oob");
 949     return _fields[i];
 950   }
 951   void set_field_at(uint i, const Type* t) {
 952     assert(i < _cnt, "oob");
 953     _fields[i] = t;
 954   }
 955 
 956   static const TypeTuple *make( uint cnt, const Type **fields );
 957   static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces);
 958   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling);
 959 
 960   // Subroutine call type with space allocated for argument types
 961   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 962   static const Type **fields( uint arg_cnt );
 963 
 964   virtual const Type *xmeet( const Type *t ) const;
 965   virtual const Type *xdual() const;    // Compute dual right now.
 966   // Convenience common pre-built types.
 967   static const TypeTuple *IFBOTH;
 968   static const TypeTuple *IFFALSE;
 969   static const TypeTuple *IFTRUE;
 970   static const TypeTuple *IFNEITHER;
 971   static const TypeTuple *LOOPBODY;
 972   static const TypeTuple *MEMBAR;
 973   static const TypeTuple *STORECONDITIONAL;
 974   static const TypeTuple *START_I2C;
 975   static const TypeTuple *INT_PAIR;
 976   static const TypeTuple *LONG_PAIR;
 977   static const TypeTuple *INT_CC_PAIR;
 978   static const TypeTuple *LONG_CC_PAIR;
 979 #ifndef PRODUCT
 980   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 981 #endif
 982 };
 983 
 984 //------------------------------TypeAry----------------------------------------
 985 // Class of Array Types
 986 class TypeAry : public Type {
 987   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
 988       _elem(elem), _size(size), _stable(stable) {}
 989 public:
 990   virtual bool eq( const Type *t ) const;
 991   virtual uint hash() const;             // Type specific hashing
 992   virtual bool singleton(void) const;    // TRUE if type is a singleton
 993   virtual bool empty(void) const;        // TRUE if type is vacuous
 994 
 995 private:
 996   const Type *_elem;            // Element type of array
 997   const TypeInt *_size;         // Elements in array
 998   const bool _stable;           // Are elements @Stable?







 999   friend class TypeAryPtr;
1000 
1001 public:
1002   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);

1003 
1004   virtual const Type *xmeet( const Type *t ) const;
1005   virtual const Type *xdual() const;    // Compute dual right now.
1006   bool ary_must_be_exact() const;  // true if arrays of such are never generic
1007   virtual const TypeAry* remove_speculative() const;
1008   virtual const Type* cleanup_speculative() const;
1009 #ifndef PRODUCT
1010   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
1011 #endif
1012 };
1013 
1014 //------------------------------TypeVect---------------------------------------
1015 // Class of Vector Types
1016 class TypeVect : public Type {
1017   const BasicType _elem_bt;  // Vector's element type
1018   const uint _length;  // Elements in vector (power of 2)
1019 
1020 protected:
1021   TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1022     _elem_bt(elem_bt), _length(length) {}
1023 
1024 public:
1025   BasicType element_basic_type() const { return _elem_bt; }
1026   uint length() const { return _length; }
1027   uint length_in_bytes() const {
1028     return _length * type2aelembytes(element_basic_type());
1029   }
1030 
1031   virtual bool eq(const Type* t) const;
1032   virtual uint hash() const;             // Type specific hashing
1033   virtual bool singleton(void) const;    // TRUE if type is a singleton
1034   virtual bool empty(void) const;        // TRUE if type is vacuous
1035 
1036   static const TypeVect* make(const BasicType elem_bt, uint length, bool is_mask = false);
1037   static const TypeVect* makemask(const BasicType elem_bt, uint length);
1038 
1039   virtual const Type* xmeet( const Type *t) const;
1040   virtual const Type* xdual() const;     // Compute dual right now.
1041 
1042   static const TypeVect* VECTA;
1043   static const TypeVect* VECTS;
1044   static const TypeVect* VECTD;
1045   static const TypeVect* VECTX;
1046   static const TypeVect* VECTY;
1047   static const TypeVect* VECTZ;
1048   static const TypeVect* VECTMASK;
1049 
1050 #ifndef PRODUCT
1051   virtual void dump2(Dict& d, uint, outputStream* st) const; // Specialized per-Type dumping
1052 #endif
1053 };
1054 
1055 class TypeVectA : public TypeVect {
1056   friend class TypeVect;
1057   TypeVectA(BasicType elem_bt, uint length) : TypeVect(VectorA, elem_bt, length) {}
1058 };
1059 
1060 class TypeVectS : public TypeVect {
1061   friend class TypeVect;
1062   TypeVectS(BasicType elem_bt, uint length) : TypeVect(VectorS, elem_bt, length) {}
1063 };
1064 
1065 class TypeVectD : public TypeVect {
1066   friend class TypeVect;
1067   TypeVectD(BasicType elem_bt, uint length) : TypeVect(VectorD, elem_bt, length) {}
1068 };
1069 
1070 class TypeVectX : public TypeVect {
1071   friend class TypeVect;
1072   TypeVectX(BasicType elem_bt, uint length) : TypeVect(VectorX, elem_bt, length) {}
1073 };
1074 
1075 class TypeVectY : public TypeVect {
1076   friend class TypeVect;
1077   TypeVectY(BasicType elem_bt, uint length) : TypeVect(VectorY, elem_bt, length) {}
1078 };
1079 
1080 class TypeVectZ : public TypeVect {
1081   friend class TypeVect;
1082   TypeVectZ(BasicType elem_bt, uint length) : TypeVect(VectorZ, elem_bt, length) {}
1083 };
1084 
1085 class TypeVectMask : public TypeVect {
1086 public:
1087   friend class TypeVect;
1088   TypeVectMask(BasicType elem_bt, uint length) : TypeVect(VectorMask, elem_bt, length) {}
1089   static const TypeVectMask* make(const BasicType elem_bt, uint length);
1090 };
1091 
1092 // Set of implemented interfaces. Referenced from TypeOopPtr and TypeKlassPtr.
1093 class TypeInterfaces : public Type {
1094 private:
1095   GrowableArrayFromArray<ciInstanceKlass*> _interfaces;
1096   uint _hash;
1097   ciInstanceKlass* _exact_klass;
1098   DEBUG_ONLY(bool _initialized;)
1099 
1100   void initialize();
1101 
1102   void verify() const NOT_DEBUG_RETURN;
1103   void compute_hash();
1104   void compute_exact_klass();
1105 
1106   TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces);
1107 
1108   NONCOPYABLE(TypeInterfaces);
1109 public:
1110   static const TypeInterfaces* make(GrowableArray<ciInstanceKlass*>* interfaces = nullptr);
1111   bool eq(const Type* other) const;
1112   bool eq(ciInstanceKlass* k) const;
1113   uint hash() const;
1114   const Type *xdual() const;
1115   void dump(outputStream* st) const;
1116   const TypeInterfaces* union_with(const TypeInterfaces* other) const;
1117   const TypeInterfaces* intersection_with(const TypeInterfaces* other) const;
1118   bool contains(const TypeInterfaces* other) const {
1119     return intersection_with(other)->eq(other);
1120   }
1121   bool empty() const { return _interfaces.length() == 0; }
1122 
1123   ciInstanceKlass* exact_klass() const;
1124   void verify_is_loaded() const NOT_DEBUG_RETURN;
1125 
1126   static int compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2);
1127   static int compare(ciInstanceKlass** k1, ciInstanceKlass** k2);
1128 
1129   const Type* xmeet(const Type* t) const;
1130 
1131   bool singleton(void) const;
1132   bool has_non_array_interface() const;
1133 };
1134 
1135 //------------------------------TypePtr----------------------------------------
1136 // Class of machine Pointer Types: raw data, instances or arrays.
1137 // If the _base enum is AnyPtr, then this refers to all of the above.
1138 // Otherwise the _base will indicate which subset of pointers is affected,
1139 // and the class will be inherited from.
1140 class TypePtr : public Type {
1141   friend class TypeNarrowPtr;
1142   friend class Type;
1143 protected:
1144   static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1145 
1146 public:
1147   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };



















1148 protected:
1149   TypePtr(TYPES t, PTR ptr, int offset,
1150           const TypePtr* speculative = nullptr,
1151           int inline_depth = InlineDepthBottom) :
1152     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1153     _ptr(ptr) {}
1154   static const PTR ptr_meet[lastPTR][lastPTR];
1155   static const PTR ptr_dual[lastPTR];
1156   static const char * const ptr_msg[lastPTR];
1157 



1158   enum {
1159     InlineDepthBottom = INT_MAX,
1160     InlineDepthTop = -InlineDepthBottom
1161   };
1162 
1163   // Extra type information profiling gave us. We propagate it the
1164   // same way the rest of the type info is propagated. If we want to
1165   // use it, then we have to emit a guard: this part of the type is
1166   // not something we know but something we speculate about the type.
1167   const TypePtr*   _speculative;
1168   // For speculative types, we record at what inlining depth the
1169   // profiling point that provided the data is. We want to favor
1170   // profile data coming from outer scopes which are likely better for
1171   // the current compilation.
1172   int _inline_depth;
1173 
1174   // utility methods to work on the speculative part of the type
1175   const TypePtr* dual_speculative() const;
1176   const TypePtr* xmeet_speculative(const TypePtr* other) const;
1177   bool eq_speculative(const TypePtr* other) const;
1178   int hash_speculative() const;
1179   const TypePtr* add_offset_speculative(intptr_t offset) const;
1180   const TypePtr* with_offset_speculative(intptr_t offset) const;
1181 
1182   // utility methods to work on the inline depth of the type
1183   int dual_inline_depth() const;
1184   int meet_inline_depth(int depth) const;
1185 
1186 #ifndef PRODUCT
1187   void dump_speculative(outputStream* st) const;
1188   void dump_inline_depth(outputStream* st) const;
1189   void dump_offset(outputStream* st) const;
1190 #endif
1191 
1192   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1193   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1194   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1195   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1196   // encountered so the right logic specific to klasses or oops can be executed.,
1197   enum MeetResult {
1198     QUICK,
1199     UNLOADED,
1200     SUBTYPE,
1201     NOT_SUBTYPE,
1202     LCA
1203   };
1204   template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1205                                                             const T* other_type, ciKlass*& res_klass, bool& res_xk);


1206 
1207   template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1208                                                   ciKlass*& res_klass, bool& res_xk);
1209 
1210   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);
1211   template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1212   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);
1213   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);
1214   template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1215   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);
1216   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);
1217   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);
1218 public:
1219   const int _offset;            // Offset into oop, with TOP & BOT
1220   const PTR _ptr;               // Pointer equivalence class
1221 
1222   int offset() const { return _offset; }
1223   PTR ptr()    const { return _ptr; }
1224 
1225   static const TypePtr *make(TYPES t, PTR ptr, int offset,
1226                              const TypePtr* speculative = nullptr,
1227                              int inline_depth = InlineDepthBottom);
1228 
1229   // Return a 'ptr' version of this type
1230   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1231 
1232   virtual intptr_t get_con() const;
1233 
1234   int xadd_offset( intptr_t offset ) const;
1235   virtual const TypePtr* add_offset(intptr_t offset) const;
1236   virtual const TypePtr* with_offset(intptr_t offset) const;

1237   virtual bool eq(const Type *t) const;
1238   virtual uint hash() const;             // Type specific hashing
1239 
1240   virtual bool singleton(void) const;    // TRUE if type is a singleton
1241   virtual bool empty(void) const;        // TRUE if type is vacuous
1242   virtual const Type *xmeet( const Type *t ) const;
1243   virtual const Type *xmeet_helper( const Type *t ) const;
1244   int meet_offset( int offset ) const;
1245   int dual_offset( ) const;
1246   virtual const Type *xdual() const;    // Compute dual right now.
1247 
1248   // meet, dual and join over pointer equivalence sets
1249   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1250   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1251 
1252   // This is textually confusing unless one recalls that
1253   // join(t) == dual()->meet(t->dual())->dual().
1254   PTR join_ptr( const PTR in_ptr ) const {
1255     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1256   }
1257 
1258   // Speculative type helper methods.
1259   virtual const TypePtr* speculative() const { return _speculative; }
1260   int inline_depth() const                   { return _inline_depth; }
1261   virtual ciKlass* speculative_type() const;
1262   virtual ciKlass* speculative_type_not_null() const;
1263   virtual bool speculative_maybe_null() const;
1264   virtual bool speculative_always_null() const;
1265   virtual const TypePtr* remove_speculative() const;
1266   virtual const Type* cleanup_speculative() const;
1267   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1268   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1269   virtual const TypePtr* with_inline_depth(int depth) const;
1270 
1271   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1272 
















1273   // Tests for relation to centerline of type lattice:
1274   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1275   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1276   // Convenience common pre-built types.
1277   static const TypePtr *NULL_PTR;
1278   static const TypePtr *NOTNULL;
1279   static const TypePtr *BOTTOM;
1280 #ifndef PRODUCT
1281   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1282 #endif
1283 };
1284 
1285 //------------------------------TypeRawPtr-------------------------------------
1286 // Class of raw pointers, pointers to things other than Oops.  Examples
1287 // include the stack pointer, top of heap, card-marking area, handles, etc.
1288 class TypeRawPtr : public TypePtr {
1289 protected:
1290   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1291 public:
1292   virtual bool eq( const Type *t ) const;
1293   virtual uint hash() const;    // Type specific hashing
1294 
1295   const address _bits;          // Constant value, if applicable
1296 
1297   static const TypeRawPtr *make( PTR ptr );
1298   static const TypeRawPtr *make( address bits );
1299 
1300   // Return a 'ptr' version of this type
1301   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1302 
1303   virtual intptr_t get_con() const;
1304 
1305   virtual const TypePtr* add_offset(intptr_t offset) const;
1306   virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1307 
1308   virtual const Type *xmeet( const Type *t ) const;
1309   virtual const Type *xdual() const;    // Compute dual right now.
1310   // Convenience common pre-built types.
1311   static const TypeRawPtr *BOTTOM;
1312   static const TypeRawPtr *NOTNULL;
1313 #ifndef PRODUCT
1314   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1315 #endif
1316 };
1317 
1318 //------------------------------TypeOopPtr-------------------------------------
1319 // Some kind of oop (Java pointer), either instance or array.
1320 class TypeOopPtr : public TypePtr {
1321   friend class TypeAry;
1322   friend class TypePtr;
1323   friend class TypeInstPtr;
1324   friend class TypeAryPtr;
1325 protected:
1326  TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1327             const TypePtr* speculative, int inline_depth);
1328 public:
1329   virtual bool eq( const Type *t ) const;
1330   virtual uint hash() const;             // Type specific hashing
1331   virtual bool singleton(void) const;    // TRUE if type is a singleton
1332   enum {
1333    InstanceTop = -1,   // undefined instance
1334    InstanceBot = 0     // any possible instance
1335   };
1336 protected:
1337 
1338   // Oop is null, unless this is a constant oop.
1339   ciObject*     _const_oop;   // Constant oop
1340   // If _klass is null, then so is _sig.  This is an unloaded klass.
1341   ciKlass*      _klass;       // Klass object
1342 
1343   const TypeInterfaces* _interfaces;
1344 
1345   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1346   bool          _klass_is_exact;
1347   bool          _is_ptr_to_narrowoop;
1348   bool          _is_ptr_to_narrowklass;
1349   bool          _is_ptr_to_boxed_value;

1350 
1351   // If not InstanceTop or InstanceBot, indicates that this is
1352   // a particular instance of this type which is distinct.
1353   // This is the node index of the allocation node creating this instance.
1354   int           _instance_id;
1355 
1356   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1357 
1358   int dual_instance_id() const;
1359   int meet_instance_id(int uid) const;
1360 
1361   const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1362 
1363   // Do not allow interface-vs.-noninterface joins to collapse to top.
1364   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1365 
1366   virtual ciKlass* exact_klass_helper() const { return nullptr; }
1367   virtual ciKlass* klass() const { return _klass;     }
1368 
1369 #ifndef PRODUCT
1370   void dump_instance_id(outputStream* st) const;
1371 #endif // PRODUCT
1372 
1373 public:
1374 
1375   bool is_java_subtype_of(const TypeOopPtr* other) const {
1376     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1377   }
1378 
1379   bool is_same_java_type_as(const TypePtr* other) const {
1380     return is_same_java_type_as_helper(other->is_oopptr());
1381   }
1382 
1383   virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1384     ShouldNotReachHere(); return false;
1385   }
1386 
1387   bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1388     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1389   }
1390   virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1391   virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1392 
1393 
1394   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1395   // Respects UseUniqueSubclasses.
1396   // If the klass is final, the resulting type will be exact.
1397   static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1398     return make_from_klass_common(klass, true, false, interface_handling);
1399   }
1400   // Same as before, but will produce an exact type, even if
1401   // the klass is not final, as long as it has exactly one implementation.
1402   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1403     return make_from_klass_common(klass, true, true, interface_handling);
1404   }
1405   // Same as before, but does not respects UseUniqueSubclasses.
1406   // Use this only for creating array element types.
1407   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1408     return make_from_klass_common(klass, false, false, interface_handling);
1409   }
1410   // Creates a singleton type given an object.
1411   // If the object cannot be rendered as a constant,
1412   // may return a non-singleton type.
1413   // If require_constant, produce a null if a singleton is not possible.
1414   static const TypeOopPtr* make_from_constant(ciObject* o,
1415                                               bool require_constant = false);
1416 
1417   // Make a generic (unclassed) pointer to an oop.
1418   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1419                                 const TypePtr* speculative = nullptr,
1420                                 int inline_depth = InlineDepthBottom);
1421 
1422   ciObject* const_oop()    const { return _const_oop; }
1423   // Exact klass, possibly an interface or an array of interface
1424   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1425   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1426 
1427   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1428   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1429 
1430   // Returns true if this pointer points at memory which contains a
1431   // compressed oop references.
1432   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1433   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1434   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }

1435   bool is_known_instance()       const { return _instance_id > 0; }
1436   int  instance_id()             const { return _instance_id; }
1437   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }



1438 
1439   virtual intptr_t get_con() const;
1440 
1441   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1442 
1443   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1444 
1445   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1446 
1447   // corresponding pointer to klass, for a given instance
1448   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1449 
1450   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1451   virtual const TypePtr* add_offset(intptr_t offset) const;
1452 
1453   // Speculative type helper methods.
1454   virtual const TypeOopPtr* remove_speculative() const;
1455   virtual const Type* cleanup_speculative() const;
1456   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1457   virtual const TypePtr* with_inline_depth(int depth) const;
1458 
1459   virtual const TypePtr* with_instance_id(int instance_id) const;
1460 
1461   virtual const Type *xdual() const;    // Compute dual right now.
1462   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1463   virtual const Type *xmeet_helper(const Type *t) const;
1464 
1465   // Convenience common pre-built type.
1466   static const TypeOopPtr *BOTTOM;
1467 #ifndef PRODUCT
1468   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1469 #endif
1470 private:
1471   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1472     return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact());
1473   }
1474 
1475   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const {
1476     ShouldNotReachHere(); return false;
1477   }
1478 
1479   virtual const TypeInterfaces* interfaces() const {
1480     return _interfaces;
1481   };
1482 
1483   const TypeOopPtr* is_reference_type(const Type* other) const {
1484     return other->isa_oopptr();
1485   }
1486 
1487   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1488     return other->isa_aryptr();
1489   }
1490 
1491   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1492     return other->isa_instptr();
1493   }
1494 };
1495 
1496 //------------------------------TypeInstPtr------------------------------------
1497 // Class of Java object pointers, pointing either to non-array Java instances
1498 // or to a Klass* (including array klasses).
1499 class TypeInstPtr : public TypeOopPtr {
1500   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1501               const TypePtr* speculative, int inline_depth);




1502   virtual bool eq( const Type *t ) const;
1503   virtual uint hash() const;             // Type specific hashing
1504 
1505   ciKlass* exact_klass_helper() const;
1506 
1507 public:
1508 
1509   // Instance klass, ignoring any interface
1510   ciInstanceKlass* instance_klass() const {
1511     assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1512     return klass()->as_instance_klass();
1513   }
1514 
1515   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1516   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1517   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1518 
1519   // Make a pointer to a constant oop.
1520   static const TypeInstPtr *make(ciObject* o) {
1521     ciKlass* k = o->klass();
1522     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1523     return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1524   }
1525   // Make a pointer to a constant oop with offset.
1526   static const TypeInstPtr *make(ciObject* o, int offset) {
1527     ciKlass* k = o->klass();
1528     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1529     return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1530   }
1531 
1532   // Make a pointer to some value of type klass.
1533   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1534     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1535     return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1536   }
1537 
1538   // Make a pointer to some non-polymorphic value of exactly type klass.
1539   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1540     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1541     return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1542   }
1543 
1544   // Make a pointer to some value of type klass with offset.
1545   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1546     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1547     return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1548   }
1549 
1550   static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,


1551                                  int instance_id = InstanceBot,
1552                                  const TypePtr* speculative = nullptr,
1553                                  int inline_depth = InlineDepthBottom);
1554 
1555   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {

1556     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1557     return make(ptr, k, interfaces, xk, o, offset, instance_id);
1558   }
1559 
1560   /** Create constant type for a constant boxed value */
1561   const Type* get_const_boxed_value() const;
1562 
1563   // If this is a java.lang.Class constant, return the type for it or null.
1564   // Pass to Type::get_const_type to turn it to a type, which will usually
1565   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1566   ciType* java_mirror_type() const;
1567 
1568   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1569 
1570   virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1571 
1572   virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1573 

1574   virtual const TypePtr* add_offset(intptr_t offset) const;
1575   virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1576 
1577   // Speculative type helper methods.
1578   virtual const TypeInstPtr* remove_speculative() const;
1579   const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1580   virtual const TypePtr* with_inline_depth(int depth) const;
1581   virtual const TypePtr* with_instance_id(int instance_id) const;
1582 








1583   // the core of the computation of the meet of 2 types
1584   virtual const Type *xmeet_helper(const Type *t) const;
1585   virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1586   virtual const Type *xdual() const;    // Compute dual right now.
1587 
1588   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1589 


1590   // Convenience common pre-built types.
1591   static const TypeInstPtr *NOTNULL;
1592   static const TypeInstPtr *BOTTOM;
1593   static const TypeInstPtr *MIRROR;
1594   static const TypeInstPtr *MARK;
1595   static const TypeInstPtr *KLASS;
1596 #ifndef PRODUCT
1597   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1598 #endif
1599 
1600 private:
1601   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1602 
1603   virtual bool is_meet_same_type_as(const TypePtr* other) const {
1604     return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1605   }
1606 
1607 };
1608 
1609 //------------------------------TypeAryPtr-------------------------------------
1610 // Class of Java array pointers
1611 class TypeAryPtr : public TypeOopPtr {
1612   friend class Type;
1613   friend class TypePtr;

1614   friend class TypeInterfaces;
1615 
1616   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1617               int offset, int instance_id, bool is_autobox_cache,
1618               const TypePtr* speculative, int inline_depth)
1619     : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1620     _ary(ary),
1621     _is_autobox_cache(is_autobox_cache)

1622  {
1623     int dummy;
1624     bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1625 
1626     if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1627         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1628         _offset != arrayOopDesc::klass_offset_in_bytes()) {
1629       _is_ptr_to_narrowoop = true;
1630     }
1631 
1632   }
1633   virtual bool eq( const Type *t ) const;
1634   virtual uint hash() const;    // Type specific hashing
1635   const TypeAry *_ary;          // Array we point into
1636   const bool     _is_autobox_cache;






1637 
1638   ciKlass* compute_klass() const;
1639 
1640   // A pointer to delay allocation to Type::Initialize_shared()
1641 
1642   static const TypeInterfaces* _array_interfaces;
1643   ciKlass* exact_klass_helper() const;
1644   // Only guaranteed non null for array of basic types
1645   ciKlass* klass() const;
1646 
1647 public:
1648 
1649   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1650   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1651   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1652 
1653   // returns base element type, an instance klass (and not interface) for object arrays
1654   const Type* base_element_type(int& dims) const;
1655 
1656   // Accessors
1657   bool  is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1658 
1659   const TypeAry* ary() const  { return _ary; }
1660   const Type*    elem() const { return _ary->_elem; }
1661   const TypeInt* size() const { return _ary->_size; }
1662   bool      is_stable() const { return _ary->_stable; }
1663 







1664   bool is_autobox_cache() const { return _is_autobox_cache; }
1665 
1666   static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1667                                 int instance_id = InstanceBot,
1668                                 const TypePtr* speculative = nullptr,
1669                                 int inline_depth = InlineDepthBottom);
1670   // Constant pointer to array
1671   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1672                                 int instance_id = InstanceBot,
1673                                 const TypePtr* speculative = nullptr,
1674                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);

1675 
1676   // Return a 'ptr' version of this type
1677   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1678 
1679   virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1680 
1681   virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1682 
1683   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1684   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1685 
1686   virtual bool empty(void) const;        // TRUE if type is vacuous
1687   virtual const TypePtr *add_offset( intptr_t offset ) const;
1688   virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1689   const TypeAryPtr* with_ary(const TypeAry* ary) const;
1690 
1691   // Speculative type helper methods.
1692   virtual const TypeAryPtr* remove_speculative() const;

1693   virtual const TypePtr* with_inline_depth(int depth) const;
1694   virtual const TypePtr* with_instance_id(int instance_id) const;
1695 
1696   // the core of the computation of the meet of 2 types
1697   virtual const Type *xmeet_helper(const Type *t) const;
1698   virtual const Type *xdual() const;    // Compute dual right now.
1699 










1700   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1701   int stable_dimension() const;
1702 
1703   const TypeAryPtr* cast_to_autobox_cache() const;
1704 
1705   static jint max_array_length(BasicType etype) ;







1706   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1707 


1708   // Convenience common pre-built types.
1709   static const TypeAryPtr* BOTTOM;
1710   static const TypeAryPtr* RANGE;
1711   static const TypeAryPtr* OOPS;
1712   static const TypeAryPtr* NARROWOOPS;
1713   static const TypeAryPtr* BYTES;
1714   static const TypeAryPtr* SHORTS;
1715   static const TypeAryPtr* CHARS;
1716   static const TypeAryPtr* INTS;
1717   static const TypeAryPtr* LONGS;
1718   static const TypeAryPtr* FLOATS;
1719   static const TypeAryPtr* DOUBLES;

1720   // selects one of the above:
1721   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1722     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1723     return _array_body_type[elem];
1724   }
1725   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1726   // sharpen the type of an int which is used as an array size
1727 #ifndef PRODUCT
1728   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1729 #endif
1730 private:
1731   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1732 };
1733 
1734 //------------------------------TypeMetadataPtr-------------------------------------
1735 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1736 class TypeMetadataPtr : public TypePtr {
1737 protected:
1738   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1739   // Do not allow interface-vs.-noninterface joins to collapse to top.
1740   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1741 public:
1742   virtual bool eq( const Type *t ) const;
1743   virtual uint hash() const;             // Type specific hashing
1744   virtual bool singleton(void) const;    // TRUE if type is a singleton
1745 
1746 private:
1747   ciMetadata*   _metadata;
1748 
1749 public:
1750   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1751 
1752   static const TypeMetadataPtr* make(ciMethod* m);
1753   static const TypeMetadataPtr* make(ciMethodData* m);
1754 
1755   ciMetadata* metadata() const { return _metadata; }
1756 
1757   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1758 
1759   virtual const TypePtr *add_offset( intptr_t offset ) const;
1760 
1761   virtual const Type *xmeet( const Type *t ) const;
1762   virtual const Type *xdual() const;    // Compute dual right now.
1763 
1764   virtual intptr_t get_con() const;
1765 
1766   // Convenience common pre-built types.
1767   static const TypeMetadataPtr *BOTTOM;
1768 
1769 #ifndef PRODUCT
1770   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1771 #endif
1772 };
1773 
1774 //------------------------------TypeKlassPtr-----------------------------------
1775 // Class of Java Klass pointers
1776 class TypeKlassPtr : public TypePtr {
1777   friend class TypeInstKlassPtr;
1778   friend class TypeAryKlassPtr;
1779   friend class TypePtr;
1780 protected:
1781   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset);
1782 
1783   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1784 
1785 public:
1786   virtual bool eq( const Type *t ) const;
1787   virtual uint hash() const;
1788   virtual bool singleton(void) const;    // TRUE if type is a singleton
1789 
1790 protected:
1791 
1792   ciKlass* _klass;
1793   const TypeInterfaces* _interfaces;
1794   const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1795   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1796   virtual ciKlass* exact_klass_helper() const;
1797   virtual ciKlass* klass() const { return  _klass; }
1798 
1799 public:
1800 
1801   bool is_java_subtype_of(const TypeKlassPtr* other) const {
1802     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1803   }
1804   bool is_same_java_type_as(const TypePtr* other) const {
1805     return is_same_java_type_as_helper(other->is_klassptr());
1806   }
1807 
1808   bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1809     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1810   }
1811   virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1812   virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1813   virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1814 
1815   // Exact klass, possibly an interface or an array of interface
1816   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1817   virtual bool klass_is_exact()    const { return _ptr == Constant; }
1818 
1819   static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1820   static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces);
1821 
1822   virtual bool  is_loaded() const { return _klass->is_loaded(); }
1823 
1824   virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1825 
1826   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1827 
1828   // corresponding pointer to instance, for a given class
1829   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1830 
1831   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1832   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1833   virtual const Type    *xdual() const { ShouldNotReachHere(); return nullptr; }
1834 
1835   virtual intptr_t get_con() const;
1836 
1837   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1838 


1839   virtual const TypeKlassPtr* try_improve() const { return this; }
1840 
1841 private:
1842   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1843     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1844   }
1845 
1846   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1847     ShouldNotReachHere(); return false;
1848   }
1849 
1850   virtual const TypeInterfaces* interfaces() const {
1851     return _interfaces;
1852   };
1853 
1854   const TypeKlassPtr* is_reference_type(const Type* other) const {
1855     return other->isa_klassptr();
1856   }
1857 
1858   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1859     return other->isa_aryklassptr();
1860   }
1861 
1862   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1863     return other->isa_instklassptr();
1864   }
1865 };
1866 
1867 // Instance klass pointer, mirrors TypeInstPtr
1868 class TypeInstKlassPtr : public TypeKlassPtr {


1869 
1870   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1871     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {

1872     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1873   }
1874 
1875   virtual bool must_be_exact() const;
1876 
1877 public:
1878   // Instance klass ignoring any interface
1879   ciInstanceKlass* instance_klass() const {
1880     assert(!klass()->is_interface(), "");
1881     return klass()->as_instance_klass();
1882   }
1883 
1884   bool might_be_an_array() const;
1885 
1886   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1887   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1888   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1889 


1890   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1891     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1892     return make(TypePtr::Constant, k, interfaces, 0);
1893   }
1894   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1895 
1896   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {



1897     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1898     return make(ptr, k, interfaces, offset);
1899   }
1900 
1901   virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1902 
1903   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1904 
1905   // corresponding pointer to instance, for a given class
1906   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1907   virtual uint hash() const;
1908   virtual bool eq(const Type *t) const;
1909 


1910   virtual const TypePtr *add_offset( intptr_t offset ) const;
1911   virtual const Type    *xmeet( const Type *t ) const;
1912   virtual const Type    *xdual() const;
1913   virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1914 
1915   virtual const TypeKlassPtr* try_improve() const;
1916 








1917   // Convenience common pre-built types.
1918   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1919   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1920 
1921 #ifndef PRODUCT
1922   virtual void dump2(Dict& d, uint depth, outputStream* st) const;
1923 #endif // PRODUCT
1924 
1925 private:
1926   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1927 };
1928 
1929 // Array klass pointer, mirrors TypeAryPtr
1930 class TypeAryKlassPtr : public TypeKlassPtr {
1931   friend class TypeInstKlassPtr;
1932   friend class Type;
1933   friend class TypePtr;
1934 
1935   const Type *_elem;






1936 
1937   static const TypeInterfaces* _array_interfaces;
1938   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1939     : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1940     assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1941   }
1942 
1943   virtual ciKlass* exact_klass_helper() const;
1944   // Only guaranteed non null for array of basic types
1945   virtual ciKlass* klass() const;
1946 
1947   virtual bool must_be_exact() const;
1948 
























1949 public:
1950 
1951   // returns base element type, an instance klass (and not interface) for object arrays
1952   const Type* base_element_type(int& dims) const;
1953 
1954   static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1955 
1956   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1957   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1958   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1959 
1960   bool  is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1961 
1962   static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1963   static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1964 



1965   const Type *elem() const { return _elem; }
1966 
1967   virtual bool eq(const Type *t) const;
1968   virtual uint hash() const;             // Type specific hashing
1969 
1970   virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
1971 
1972   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1973 
1974   // corresponding pointer to instance, for a given class
1975   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1976 
1977   virtual const TypePtr *add_offset( intptr_t offset ) const;
1978   virtual const Type    *xmeet( const Type *t ) const;
1979   virtual const Type    *xdual() const;      // Compute dual right now.
1980 
1981   virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
1982 
1983   virtual bool empty(void) const {
1984     return TypeKlassPtr::empty() || _elem->empty();
1985   }
1986 








1987 #ifndef PRODUCT
1988   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1989 #endif
1990 private:
1991   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1992 };
1993 
1994 class TypeNarrowPtr : public Type {
1995 protected:
1996   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1997 
1998   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1999                                                   _ptrtype(ptrtype) {
2000     assert(ptrtype->offset() == 0 ||
2001            ptrtype->offset() == OffsetBot ||
2002            ptrtype->offset() == OffsetTop, "no real offsets");
2003   }
2004 
2005   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2006   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
2007   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
2008   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
2009   // Do not allow interface-vs.-noninterface joins to collapse to top.
2010   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
2011 public:
2012   virtual bool eq( const Type *t ) const;
2013   virtual uint hash() const;             // Type specific hashing
2014   virtual bool singleton(void) const;    // TRUE if type is a singleton
2015 
2016   virtual const Type *xmeet( const Type *t ) const;
2017   virtual const Type *xdual() const;    // Compute dual right now.
2018 
2019   virtual intptr_t get_con() const;
2020 
2021   virtual bool empty(void) const;        // TRUE if type is vacuous
2022 
2023   // returns the equivalent ptr type for this compressed pointer
2024   const TypePtr *get_ptrtype() const {
2025     return _ptrtype;
2026   }
2027 
2028   bool is_known_instance() const {
2029     return _ptrtype->is_known_instance();
2030   }
2031 
2032 #ifndef PRODUCT
2033   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2034 #endif
2035 };
2036 
2037 //------------------------------TypeNarrowOop----------------------------------
2038 // A compressed reference to some kind of Oop.  This type wraps around
2039 // a preexisting TypeOopPtr and forwards most of it's operations to
2040 // the underlying type.  It's only real purpose is to track the
2041 // oopness of the compressed oop value when we expose the conversion
2042 // between the normal and the compressed form.
2043 class TypeNarrowOop : public TypeNarrowPtr {
2044 protected:
2045   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
2046   }
2047 
2048   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2049     return t->isa_narrowoop();
2050   }
2051 
2052   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2053     return t->is_narrowoop();
2054   }
2055 
2056   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2057     return new TypeNarrowOop(t);
2058   }
2059 
2060   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2061     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
2062   }
2063 
2064 public:
2065 
2066   static const TypeNarrowOop *make( const TypePtr* type);
2067 
2068   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
2069     return make(TypeOopPtr::make_from_constant(con, require_constant));
2070   }
2071 
2072   static const TypeNarrowOop *BOTTOM;
2073   static const TypeNarrowOop *NULL_PTR;
2074 
2075   virtual const TypeNarrowOop* remove_speculative() const;
2076   virtual const Type* cleanup_speculative() const;
2077 
2078 #ifndef PRODUCT
2079   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2080 #endif
2081 };
2082 
2083 //------------------------------TypeNarrowKlass----------------------------------
2084 // A compressed reference to klass pointer.  This type wraps around a
2085 // preexisting TypeKlassPtr and forwards most of it's operations to
2086 // the underlying type.
2087 class TypeNarrowKlass : public TypeNarrowPtr {
2088 protected:
2089   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
2090   }
2091 
2092   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2093     return t->isa_narrowklass();
2094   }
2095 
2096   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2097     return t->is_narrowklass();
2098   }
2099 
2100   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2101     return new TypeNarrowKlass(t);
2102   }
2103 
2104   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2105     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2106   }
2107 
2108 public:
2109   static const TypeNarrowKlass *make( const TypePtr* type);
2110 
2111   // static const TypeNarrowKlass *BOTTOM;
2112   static const TypeNarrowKlass *NULL_PTR;
2113 
2114 #ifndef PRODUCT
2115   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2116 #endif
2117 };
2118 
2119 //------------------------------TypeFunc---------------------------------------
2120 // Class of Array Types
2121 class TypeFunc : public Type {
2122   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}

2123   virtual bool eq( const Type *t ) const;
2124   virtual uint hash() const;             // Type specific hashing
2125   virtual bool singleton(void) const;    // TRUE if type is a singleton
2126   virtual bool empty(void) const;        // TRUE if type is vacuous
2127 
2128   const TypeTuple* const _domain;     // Domain of inputs
2129   const TypeTuple* const _range;      // Range of results











2130 
2131 public:
2132   // Constants are shared among ADLC and VM
2133   enum { Control    = AdlcVMDeps::Control,
2134          I_O        = AdlcVMDeps::I_O,
2135          Memory     = AdlcVMDeps::Memory,
2136          FramePtr   = AdlcVMDeps::FramePtr,
2137          ReturnAdr  = AdlcVMDeps::ReturnAdr,
2138          Parms      = AdlcVMDeps::Parms
2139   };
2140 
2141 
2142   // Accessors:
2143   const TypeTuple* domain() const { return _domain; }
2144   const TypeTuple* range()  const { return _range; }
2145 
2146   static const TypeFunc *make(ciMethod* method);
2147   static const TypeFunc *make(ciSignature signature, const Type* extra);



2148   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2149 
2150   virtual const Type *xmeet( const Type *t ) const;
2151   virtual const Type *xdual() const;    // Compute dual right now.
2152 
2153   BasicType return_type() const;
2154 


2155 #ifndef PRODUCT
2156   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2157 #endif
2158   // Convenience common pre-built types.
2159 };
2160 
2161 //------------------------------accessors--------------------------------------
2162 inline bool Type::is_ptr_to_narrowoop() const {
2163 #ifdef _LP64
2164   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2165 #else
2166   return false;
2167 #endif
2168 }
2169 
2170 inline bool Type::is_ptr_to_narrowklass() const {
2171 #ifdef _LP64
2172   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2173 #else
2174   return false;
2175 #endif
2176 }
2177 
2178 inline float Type::getf() const {
2179   assert( _base == FloatCon, "Not a FloatCon" );
2180   return ((TypeF*)this)->_f;
2181 }
2182 
2183 inline short Type::geth() const {
2184   assert(_base == HalfFloatCon, "Not a HalfFloatCon");
2185   return ((TypeH*)this)->_f;
2186 }
2187 
2188 inline double Type::getd() const {
2189   assert( _base == DoubleCon, "Not a DoubleCon" );
2190   return ((TypeD*)this)->_d;
2191 }
2192 
2193 inline const TypeInteger *Type::is_integer(BasicType bt) const {
2194   assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int");
2195   return (TypeInteger*)this;
2196 }
2197 
2198 inline const TypeInteger *Type::isa_integer(BasicType bt) const {
2199   return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : nullptr);
2200 }
2201 
2202 inline const TypeInt *Type::is_int() const {
2203   assert( _base == Int, "Not an Int" );
2204   return (TypeInt*)this;
2205 }
2206 
2207 inline const TypeInt *Type::isa_int() const {
2208   return ( _base == Int ? (TypeInt*)this : nullptr);
2209 }
2210 
2211 inline const TypeLong *Type::is_long() const {
2212   assert( _base == Long, "Not a Long" );
2213   return (TypeLong*)this;
2214 }
2215 
2216 inline const TypeLong *Type::isa_long() const {
2217   return ( _base == Long ? (TypeLong*)this : nullptr);
2218 }
2219 
2220 inline const TypeH* Type::isa_half_float() const {
2221   return ((_base == HalfFloatTop ||
2222            _base == HalfFloatCon ||
2223            _base == HalfFloatBot) ? (TypeH*)this : nullptr);
2224 }
2225 
2226 inline const TypeH* Type::is_half_float_constant() const {
2227   assert( _base == HalfFloatCon, "Not a HalfFloat" );
2228   return (TypeH*)this;
2229 }
2230 
2231 inline const TypeH* Type::isa_half_float_constant() const {
2232   return (_base == HalfFloatCon ? (TypeH*)this : nullptr);
2233 }
2234 
2235 inline const TypeF *Type::isa_float() const {
2236   return ((_base == FloatTop ||
2237            _base == FloatCon ||
2238            _base == FloatBot) ? (TypeF*)this : nullptr);
2239 }
2240 
2241 inline const TypeF *Type::is_float_constant() const {
2242   assert( _base == FloatCon, "Not a Float" );
2243   return (TypeF*)this;
2244 }
2245 
2246 inline const TypeF *Type::isa_float_constant() const {
2247   return ( _base == FloatCon ? (TypeF*)this : nullptr);
2248 }
2249 
2250 inline const TypeD *Type::isa_double() const {
2251   return ((_base == DoubleTop ||
2252            _base == DoubleCon ||
2253            _base == DoubleBot) ? (TypeD*)this : nullptr);
2254 }
2255 
2256 inline const TypeD *Type::is_double_constant() const {
2257   assert( _base == DoubleCon, "Not a Double" );
2258   return (TypeD*)this;
2259 }
2260 
2261 inline const TypeD *Type::isa_double_constant() const {
2262   return ( _base == DoubleCon ? (TypeD*)this : nullptr);
2263 }
2264 
2265 inline const TypeTuple *Type::is_tuple() const {
2266   assert( _base == Tuple, "Not a Tuple" );
2267   return (TypeTuple*)this;
2268 }
2269 
2270 inline const TypeAry *Type::is_ary() const {
2271   assert( _base == Array , "Not an Array" );
2272   return (TypeAry*)this;
2273 }
2274 
2275 inline const TypeAry *Type::isa_ary() const {
2276   return ((_base == Array) ? (TypeAry*)this : nullptr);
2277 }
2278 
2279 inline const TypeVectMask *Type::is_vectmask() const {
2280   assert( _base == VectorMask, "Not a Vector Mask" );
2281   return (TypeVectMask*)this;
2282 }
2283 
2284 inline const TypeVectMask *Type::isa_vectmask() const {
2285   return (_base == VectorMask) ? (TypeVectMask*)this : nullptr;
2286 }
2287 
2288 inline const TypeVect *Type::is_vect() const {
2289   assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" );
2290   return (TypeVect*)this;
2291 }
2292 
2293 inline const TypeVect *Type::isa_vect() const {
2294   return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : nullptr;
2295 }
2296 
2297 inline const TypePtr *Type::is_ptr() const {
2298   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2299   assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer");
2300   return (TypePtr*)this;
2301 }
2302 
2303 inline const TypePtr *Type::isa_ptr() const {
2304   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2305   return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : nullptr;
2306 }
2307 
2308 inline const TypeOopPtr *Type::is_oopptr() const {
2309   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2310   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
2311   return (TypeOopPtr*)this;
2312 }
2313 
2314 inline const TypeOopPtr *Type::isa_oopptr() const {
2315   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2316   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : nullptr;
2317 }
2318 
2319 inline const TypeRawPtr *Type::isa_rawptr() const {
2320   return (_base == RawPtr) ? (TypeRawPtr*)this : nullptr;
2321 }
2322 
2323 inline const TypeRawPtr *Type::is_rawptr() const {
2324   assert( _base == RawPtr, "Not a raw pointer" );
2325   return (TypeRawPtr*)this;
2326 }
2327 
2328 inline const TypeInstPtr *Type::isa_instptr() const {
2329   return (_base == InstPtr) ? (TypeInstPtr*)this : nullptr;
2330 }
2331 
2332 inline const TypeInstPtr *Type::is_instptr() const {
2333   assert( _base == InstPtr, "Not an object pointer" );
2334   return (TypeInstPtr*)this;
2335 }
2336 
2337 inline const TypeAryPtr *Type::isa_aryptr() const {
2338   return (_base == AryPtr) ? (TypeAryPtr*)this : nullptr;
2339 }
2340 
2341 inline const TypeAryPtr *Type::is_aryptr() const {
2342   assert( _base == AryPtr, "Not an array pointer" );
2343   return (TypeAryPtr*)this;
2344 }
2345 
2346 inline const TypeNarrowOop *Type::is_narrowoop() const {
2347   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2348   assert(_base == NarrowOop, "Not a narrow oop" ) ;
2349   return (TypeNarrowOop*)this;
2350 }
2351 
2352 inline const TypeNarrowOop *Type::isa_narrowoop() const {
2353   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2354   return (_base == NarrowOop) ? (TypeNarrowOop*)this : nullptr;
2355 }
2356 
2357 inline const TypeNarrowKlass *Type::is_narrowklass() const {
2358   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
2359   return (TypeNarrowKlass*)this;
2360 }
2361 
2362 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
2363   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : nullptr;
2364 }
2365 
2366 inline const TypeMetadataPtr *Type::is_metadataptr() const {
2367   // MetadataPtr is the first and CPCachePtr the last
2368   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
2369   return (TypeMetadataPtr*)this;
2370 }
2371 
2372 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
2373   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : nullptr;
2374 }
2375 
2376 inline const TypeKlassPtr *Type::isa_klassptr() const {
2377   return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : nullptr;
2378 }
2379 
2380 inline const TypeKlassPtr *Type::is_klassptr() const {
2381   assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer");
2382   return (TypeKlassPtr*)this;
2383 }
2384 
2385 inline const TypeInstKlassPtr *Type::isa_instklassptr() const {
2386   return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : nullptr;
2387 }
2388 
2389 inline const TypeInstKlassPtr *Type::is_instklassptr() const {
2390   assert(_base == InstKlassPtr, "Not a klass pointer");
2391   return (TypeInstKlassPtr*)this;
2392 }
2393 
2394 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const {
2395   return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : nullptr;
2396 }
2397 
2398 inline const TypeAryKlassPtr *Type::is_aryklassptr() const {
2399   assert(_base == AryKlassPtr, "Not a klass pointer");
2400   return (TypeAryKlassPtr*)this;
2401 }
2402 
2403 inline const TypePtr* Type::make_ptr() const {
2404   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
2405                               ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
2406                                                        isa_ptr());
2407 }
2408 
2409 inline const TypeOopPtr* Type::make_oopptr() const {
2410   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
2411 }
2412 
2413 inline const TypeNarrowOop* Type::make_narrowoop() const {
2414   return (_base == NarrowOop) ? is_narrowoop() :
2415                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2416 }
2417 
2418 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2419   return (_base == NarrowKlass) ? is_narrowklass() :
2420                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2421 }
2422 
2423 inline bool Type::is_floatingpoint() const {
2424   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2425       (_base == FloatCon)  || (_base == FloatBot) ||
2426       (_base == DoubleCon) || (_base == DoubleBot) )
2427     return true;
2428   return false;
2429 }
2430 








2431 template <>
2432 inline const TypeInt* Type::cast<TypeInt>() const {
2433   return is_int();
2434 }
2435 
2436 template <>
2437 inline const TypeLong* Type::cast<TypeLong>() const {
2438   return is_long();
2439 }
2440 
2441 template <>
2442 inline const TypeInt* Type::try_cast<TypeInt>() const {
2443   return isa_int();
2444 }
2445 
2446 template <>
2447 inline const TypeLong* Type::try_cast<TypeLong>() const {
2448   return isa_long();
2449 }
2450 
2451 // ===============================================================
2452 // Things that need to be 64-bits in the 64-bit build but
2453 // 32-bits in the 32-bit build.  Done this way to get full
2454 // optimization AND strong typing.
2455 #ifdef _LP64
2456 
2457 // For type queries and asserts
2458 #define is_intptr_t  is_long
2459 #define isa_intptr_t isa_long
2460 #define find_intptr_t_type find_long_type
2461 #define find_intptr_t_con  find_long_con
2462 #define TypeX        TypeLong
2463 #define Type_X       Type::Long
2464 #define TypeX_X      TypeLong::LONG
2465 #define TypeX_ZERO   TypeLong::ZERO
2466 // For 'ideal_reg' machine registers
2467 #define Op_RegX      Op_RegL
2468 // For phase->intcon variants
2469 #define MakeConX     longcon
2470 #define ConXNode     ConLNode
2471 // For array index arithmetic
2472 #define MulXNode     MulLNode
2473 #define AndXNode     AndLNode
2474 #define OrXNode      OrLNode
2475 #define CmpXNode     CmpLNode

2476 #define SubXNode     SubLNode
2477 #define LShiftXNode  LShiftLNode
2478 // For object size computation:
2479 #define AddXNode     AddLNode
2480 #define RShiftXNode  RShiftLNode
2481 // For card marks and hashcodes
2482 #define URShiftXNode URShiftLNode
2483 // For shenandoahSupport
2484 #define LoadXNode    LoadLNode
2485 #define StoreXNode   StoreLNode
2486 // Opcodes
2487 #define Op_LShiftX   Op_LShiftL
2488 #define Op_AndX      Op_AndL
2489 #define Op_AddX      Op_AddL
2490 #define Op_SubX      Op_SubL
2491 #define Op_XorX      Op_XorL
2492 #define Op_URShiftX  Op_URShiftL
2493 #define Op_LoadX     Op_LoadL

2494 // conversions
2495 #define ConvI2X(x)   ConvI2L(x)
2496 #define ConvL2X(x)   (x)
2497 #define ConvX2I(x)   ConvL2I(x)
2498 #define ConvX2L(x)   (x)
2499 #define ConvX2UL(x)  (x)
2500 
2501 #else
2502 
2503 // For type queries and asserts
2504 #define is_intptr_t  is_int
2505 #define isa_intptr_t isa_int
2506 #define find_intptr_t_type find_int_type
2507 #define find_intptr_t_con  find_int_con
2508 #define TypeX        TypeInt
2509 #define Type_X       Type::Int
2510 #define TypeX_X      TypeInt::INT
2511 #define TypeX_ZERO   TypeInt::ZERO
2512 // For 'ideal_reg' machine registers
2513 #define Op_RegX      Op_RegI
2514 // For phase->intcon variants
2515 #define MakeConX     intcon
2516 #define ConXNode     ConINode
2517 // For array index arithmetic
2518 #define MulXNode     MulINode
2519 #define AndXNode     AndINode
2520 #define OrXNode      OrINode
2521 #define CmpXNode     CmpINode

2522 #define SubXNode     SubINode
2523 #define LShiftXNode  LShiftINode
2524 // For object size computation:
2525 #define AddXNode     AddINode
2526 #define RShiftXNode  RShiftINode
2527 // For card marks and hashcodes
2528 #define URShiftXNode URShiftINode
2529 // For shenandoahSupport
2530 #define LoadXNode    LoadINode
2531 #define StoreXNode   StoreINode
2532 // Opcodes
2533 #define Op_LShiftX   Op_LShiftI
2534 #define Op_AndX      Op_AndI
2535 #define Op_AddX      Op_AddI
2536 #define Op_SubX      Op_SubI
2537 #define Op_XorX      Op_XorI
2538 #define Op_URShiftX  Op_URShiftI
2539 #define Op_LoadX     Op_LoadI

2540 // conversions
2541 #define ConvI2X(x)   (x)
2542 #define ConvL2X(x)   ConvL2I(x)
2543 #define ConvX2I(x)   (x)
2544 #define ConvX2L(x)   ConvI2L(x)
2545 #define ConvX2UL(x)  ConvI2UL(x)
2546 
2547 #endif
2548 
2549 #endif // SHARE_OPTO_TYPE_HPP
--- EOF ---