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