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