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