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