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 const Type* remove_speculative() const                              { return this; }
 483   virtual const Type* cleanup_speculative() const                             { return this; }
 484   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != NULL; }
 485   virtual bool would_improve_ptr(bool maybe_null) const                       { return !maybe_null; }
 486   const Type* maybe_remove_speculative(bool include_speculative) const;
 487 
 488   virtual bool maybe_null() const { return true; }
 489 
 490 private:
 491   // support arrays
 492   static const BasicType _basic_type[];
 493   static const Type*        _zero_type[T_CONFLICT+1];
 494   static const Type* _const_basic_type[T_CONFLICT+1];
 495 };
 496 
 497 //------------------------------TypeF------------------------------------------
 498 // Class of Float-Constant Types.
 499 class TypeF : public Type {
 500   TypeF( float f ) : Type(FloatCon), _f(f) {};
 501 public:
 502   virtual bool eq( const Type *t ) const;
 503   virtual int  hash() const;             // Type specific hashing
 504   virtual bool singleton(void) const;    // TRUE if type is a singleton
 505   virtual bool empty(void) const;        // TRUE if type is vacuous
 506 public:
 507   const float _f;               // Float constant
 508 
 509   static const TypeF *make(float f);
 510 
 511   virtual bool        is_finite() const;  // Has a finite value
 512   virtual bool        is_nan()    const;  // Is not a number (NaN)
 513 
 514   virtual const Type *xmeet( const Type *t ) const;
 515   virtual const Type *xdual() const;    // Compute dual right now.
 516   // Convenience common pre-built types.
 517   static const TypeF *ZERO; // positive zero only
 518   static const TypeF *ONE;
 519 #ifndef PRODUCT
 520   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 521 #endif
 522 };
 523 
 524 //------------------------------TypeD------------------------------------------
 525 // Class of Double-Constant Types.
 526 class TypeD : public Type {
 527   TypeD( double d ) : Type(DoubleCon), _d(d) {};
 528 public:
 529   virtual bool eq( const Type *t ) const;
 530   virtual int  hash() const;             // Type specific hashing
 531   virtual bool singleton(void) const;    // TRUE if type is a singleton
 532   virtual bool empty(void) const;        // TRUE if type is vacuous
 533 public:
 534   const double _d;              // Double constant
 535 
 536   static const TypeD *make(double d);
 537 
 538   virtual bool        is_finite() const;  // Has a finite value
 539   virtual bool        is_nan()    const;  // Is not a number (NaN)
 540 
 541   virtual const Type *xmeet( const Type *t ) const;
 542   virtual const Type *xdual() const;    // Compute dual right now.
 543   // Convenience common pre-built types.
 544   static const TypeD *ZERO; // positive zero only
 545   static const TypeD *ONE;
 546 #ifndef PRODUCT
 547   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 548 #endif
 549 };
 550 
 551 //------------------------------TypeInt----------------------------------------
 552 // Class of integer ranges, the set of integers between a lower bound and an
 553 // upper bound, inclusive.
 554 class TypeInt : public Type {
 555   TypeInt( jint lo, jint hi, int w );
 556 protected:
 557   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
 558 
 559 public:
 560   typedef jint NativeType;
 561   virtual bool eq( const Type *t ) const;
 562   virtual int  hash() const;             // Type specific hashing
 563   virtual bool singleton(void) const;    // TRUE if type is a singleton
 564   virtual bool empty(void) const;        // TRUE if type is vacuous
 565   const jint _lo, _hi;          // Lower bound, upper bound
 566   const short _widen;           // Limit on times we widen this sucker
 567 
 568   static const TypeInt *make(jint lo);
 569   // must always specify w
 570   static const TypeInt *make(jint lo, jint hi, int w);
 571 
 572   // Check for single integer
 573   int is_con() const { return _lo==_hi; }
 574   bool is_con(int i) const { return is_con() && _lo == i; }
 575   jint get_con() const { assert( is_con(), "" );  return _lo; }
 576 
 577   virtual bool        is_finite() const;  // Has a finite value
 578 
 579   virtual const Type *xmeet( const Type *t ) const;
 580   virtual const Type *xdual() const;    // Compute dual right now.
 581   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
 582   virtual const Type *narrow( const Type *t ) const;
 583   // Do not kill _widen bits.
 584   // Convenience common pre-built types.
 585   static const TypeInt *MINUS_1;
 586   static const TypeInt *ZERO;
 587   static const TypeInt *ONE;
 588   static const TypeInt *BOOL;
 589   static const TypeInt *CC;
 590   static const TypeInt *CC_LT;  // [-1]  == MINUS_1
 591   static const TypeInt *CC_GT;  // [1]   == ONE
 592   static const TypeInt *CC_EQ;  // [0]   == ZERO
 593   static const TypeInt *CC_LE;  // [-1,0]
 594   static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
 595   static const TypeInt *BYTE;
 596   static const TypeInt *UBYTE;
 597   static const TypeInt *CHAR;
 598   static const TypeInt *SHORT;
 599   static const TypeInt *POS;
 600   static const TypeInt *POS1;
 601   static const TypeInt *INT;
 602   static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
 603   static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT
 604 
 605   static const TypeInt *as_self(const Type *t) { return t->is_int(); }
 606 #ifndef PRODUCT
 607   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
 608 #endif
 609 };
 610 
 611 
 612 //------------------------------TypeLong---------------------------------------
 613 // Class of long integer ranges, the set of integers between a lower bound and
 614 // an upper bound, inclusive.
 615 class TypeLong : public Type {
 616   TypeLong( jlong lo, jlong hi, int w );
 617 protected:
 618   // Do not kill _widen bits.
 619   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
 620 public:
 621   typedef jlong NativeType;
 622   virtual bool eq( const Type *t ) const;
 623   virtual int  hash() const;             // Type specific hashing
 624   virtual bool singleton(void) const;    // TRUE if type is a singleton
 625   virtual bool empty(void) const;        // TRUE if type is vacuous
 626 public:
 627   const jlong _lo, _hi;         // Lower bound, upper bound
 628   const short _widen;           // Limit on times we widen this sucker
 629 
 630   static const TypeLong *make(jlong lo);
 631   // must always specify w
 632   static const TypeLong *make(jlong lo, jlong hi, int w);
 633 
 634   // Check for single integer
 635   int is_con() const { return _lo==_hi; }
 636   bool is_con(int i) const { return is_con() && _lo == i; }
 637   jlong get_con() const { assert( is_con(), "" ); return _lo; }
 638 
 639   // Check for positive 32-bit value.
 640   int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
 641 
 642   virtual bool        is_finite() const;  // Has a finite value
 643 
 644 
 645   virtual const Type *xmeet( const Type *t ) const;
 646   virtual const Type *xdual() const;    // Compute dual right now.
 647   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
 648   virtual const Type *narrow( const Type *t ) const;
 649   // Convenience common pre-built types.
 650   static const TypeLong *MINUS_1;
 651   static const TypeLong *ZERO;
 652   static const TypeLong *ONE;
 653   static const TypeLong *POS;
 654   static const TypeLong *LONG;
 655   static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
 656   static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
 657   static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG
 658 
 659   // static convenience methods.
 660   static const TypeLong *as_self(const Type *t) { return t->is_long(); }
 661 
 662 #ifndef PRODUCT
 663   virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
 664 #endif
 665 };
 666 
 667 //------------------------------TypeTuple--------------------------------------
 668 // Class of Tuple Types, essentially type collections for function signatures
 669 // and class layouts.  It happens to also be a fast cache for the HotSpot
 670 // signature types.
 671 class TypeTuple : public Type {
 672   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
 673 
 674   const uint          _cnt;              // Count of fields
 675   const Type ** const _fields;           // Array of field types
 676 
 677 public:
 678   virtual bool eq( const Type *t ) const;
 679   virtual int  hash() const;             // Type specific hashing
 680   virtual bool singleton(void) const;    // TRUE if type is a singleton
 681   virtual bool empty(void) const;        // TRUE if type is vacuous
 682 
 683   // Accessors:
 684   uint cnt() const { return _cnt; }
 685   const Type* field_at(uint i) const {
 686     assert(i < _cnt, "oob");
 687     return _fields[i];
 688   }
 689   void set_field_at(uint i, const Type* t) {
 690     assert(i < _cnt, "oob");
 691     _fields[i] = t;
 692   }
 693 
 694   static const TypeTuple *make( uint cnt, const Type **fields );
 695   static const TypeTuple *make_range(ciSignature *sig, bool ret_vt_fields = false);
 696   static const TypeTuple *make_range(ciType *ret_type, bool ret_vt_fields = false);
 697   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, bool vt_fields_as_args = false);
 698 
 699   // Subroutine call type with space allocated for argument types
 700   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 701   static const Type **fields( uint arg_cnt );
 702 
 703   virtual const Type *xmeet( const Type *t ) const;
 704   virtual const Type *xdual() const;    // Compute dual right now.
 705   // Convenience common pre-built types.
 706   static const TypeTuple *IFBOTH;
 707   static const TypeTuple *IFFALSE;
 708   static const TypeTuple *IFTRUE;
 709   static const TypeTuple *IFNEITHER;
 710   static const TypeTuple *LOOPBODY;
 711   static const TypeTuple *MEMBAR;
 712   static const TypeTuple *STORECONDITIONAL;
 713   static const TypeTuple *START_I2C;
 714   static const TypeTuple *INT_PAIR;
 715   static const TypeTuple *LONG_PAIR;
 716   static const TypeTuple *INT_CC_PAIR;
 717   static const TypeTuple *LONG_CC_PAIR;
 718 #ifndef PRODUCT
 719   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 720 #endif
 721 };
 722 
 723 //------------------------------TypeAry----------------------------------------
 724 // Class of Array Types
 725 class TypeAry : public Type {
 726   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
 727       _elem(elem), _size(size), _stable(stable) {}
 728 public:
 729   virtual bool eq( const Type *t ) const;
 730   virtual int  hash() const;             // Type specific hashing
 731   virtual bool singleton(void) const;    // TRUE if type is a singleton
 732   virtual bool empty(void) const;        // TRUE if type is vacuous
 733 
 734 private:
 735   const Type *_elem;            // Element type of array
 736   const TypeInt *_size;         // Elements in array
 737   const bool _stable;           // Are elements @Stable?
 738   friend class TypeAryPtr;
 739 
 740 public:
 741   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
 742 
 743   virtual const Type *xmeet( const Type *t ) const;
 744   virtual const Type *xdual() const;    // Compute dual right now.
 745   bool ary_must_be_exact() const;  // true if arrays of such are never generic
 746   virtual const Type* remove_speculative() const;
 747   virtual const Type* cleanup_speculative() const;
 748 #ifdef ASSERT
 749   // One type is interface, the other is oop
 750   virtual bool interface_vs_oop(const Type *t) const;
 751 #endif
 752 #ifndef PRODUCT
 753   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 754 #endif
 755 };
 756 
 757 
 758 //------------------------------TypeValue---------------------------------------
 759 // Class of Value Type Types
 760 class TypeValueType : public Type {
 761 private:
 762   ciValueKlass* _vk;
 763 
 764 protected:
 765   TypeValueType(ciValueKlass* vk) : Type(ValueType) { _vk = vk; }
 766 
 767 public:
 768   static const TypeValueType* make(ciValueKlass* vk);
 769   ciValueKlass* value_klass() const { return _vk; }
 770 
 771   virtual bool eq(const Type* t) const;
 772   virtual int  hash() const;             // Type specific hashing
 773   virtual bool singleton(void) const;    // TRUE if type is a singleton
 774   virtual bool empty(void) const;        // TRUE if type is vacuous
 775 
 776   virtual const Type* xmeet(const Type* t) const;
 777   virtual const Type* xdual() const;     // Compute dual right now.
 778 
 779 #ifndef PRODUCT
 780   virtual void dump2(Dict &d, uint, outputStream* st) const; // Specialized per-Type dumping
 781 #endif
 782 };
 783 
 784 //------------------------------TypeVect---------------------------------------
 785 // Class of Vector Types
 786 class TypeVect : public Type {
 787   const Type*   _elem;  // Vector's element type
 788   const uint  _length;  // Elements in vector (power of 2)
 789 
 790 protected:
 791   TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
 792     _elem(elem), _length(length) {}
 793 
 794 public:
 795   const Type* element_type() const { return _elem; }
 796   BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
 797   uint length() const { return _length; }
 798   uint length_in_bytes() const {
 799    return _length * type2aelembytes(element_basic_type());
 800   }
 801 
 802   virtual bool eq(const Type *t) const;
 803   virtual int  hash() const;             // Type specific hashing
 804   virtual bool singleton(void) const;    // TRUE if type is a singleton
 805   virtual bool empty(void) const;        // TRUE if type is vacuous
 806 
 807   static const TypeVect *make(const BasicType elem_bt, uint length) {
 808     // Use bottom primitive type.
 809     return make(get_const_basic_type(elem_bt), length);
 810   }
 811   // Used directly by Replicate nodes to construct singleton vector.
 812   static const TypeVect *make(const Type* elem, uint length);
 813 
 814   virtual const Type *xmeet( const Type *t) const;
 815   virtual const Type *xdual() const;     // Compute dual right now.
 816 
 817   static const TypeVect *VECTS;
 818   static const TypeVect *VECTD;
 819   static const TypeVect *VECTX;
 820   static const TypeVect *VECTY;
 821   static const TypeVect *VECTZ;
 822 
 823 #ifndef PRODUCT
 824   virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
 825 #endif
 826 };
 827 
 828 class TypeVectS : public TypeVect {
 829   friend class TypeVect;
 830   TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
 831 };
 832 
 833 class TypeVectD : public TypeVect {
 834   friend class TypeVect;
 835   TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
 836 };
 837 
 838 class TypeVectX : public TypeVect {
 839   friend class TypeVect;
 840   TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
 841 };
 842 
 843 class TypeVectY : public TypeVect {
 844   friend class TypeVect;
 845   TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
 846 };
 847 
 848 class TypeVectZ : public TypeVect {
 849   friend class TypeVect;
 850   TypeVectZ(const Type* elem, uint length) : TypeVect(VectorZ, elem, length) {}
 851 };
 852 
 853 //------------------------------TypePtr----------------------------------------
 854 // Class of machine Pointer Types: raw data, instances or arrays.
 855 // If the _base enum is AnyPtr, then this refers to all of the above.
 856 // Otherwise the _base will indicate which subset of pointers is affected,
 857 // and the class will be inherited from.
 858 class TypePtr : public Type {
 859   friend class TypeNarrowPtr;
 860 public:
 861   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
 862 protected:
 863   TypePtr(TYPES t, PTR ptr, Offset offset,
 864           const TypePtr* speculative = NULL,
 865           int inline_depth = InlineDepthBottom) :
 866     Type(t), _ptr(ptr), _offset(offset), _speculative(speculative),
 867     _inline_depth(inline_depth) {}
 868   static const PTR ptr_meet[lastPTR][lastPTR];
 869   static const PTR ptr_dual[lastPTR];
 870   static const char * const ptr_msg[lastPTR];
 871 
 872   enum {
 873     InlineDepthBottom = INT_MAX,
 874     InlineDepthTop = -InlineDepthBottom
 875   };
 876 
 877   // Extra type information profiling gave us. We propagate it the
 878   // same way the rest of the type info is propagated. If we want to
 879   // use it, then we have to emit a guard: this part of the type is
 880   // not something we know but something we speculate about the type.
 881   const TypePtr*   _speculative;
 882   // For speculative types, we record at what inlining depth the
 883   // profiling point that provided the data is. We want to favor
 884   // profile data coming from outer scopes which are likely better for
 885   // the current compilation.
 886   int _inline_depth;
 887 
 888   // utility methods to work on the speculative part of the type
 889   const TypePtr* dual_speculative() const;
 890   const TypePtr* xmeet_speculative(const TypePtr* other) const;
 891   bool eq_speculative(const TypePtr* other) const;
 892   int hash_speculative() const;
 893   const TypePtr* add_offset_speculative(intptr_t offset) const;
 894 #ifndef PRODUCT
 895   void dump_speculative(outputStream *st) const;
 896 #endif
 897 
 898   // utility methods to work on the inline depth of the type
 899   int dual_inline_depth() const;
 900   int meet_inline_depth(int depth) const;
 901 #ifndef PRODUCT
 902   void dump_inline_depth(outputStream *st) const;
 903 #endif
 904 
 905 public:
 906   const Offset _offset;         // Offset into oop, with TOP & BOT
 907   const PTR _ptr;               // Pointer equivalence class
 908 
 909   const int offset() const { return _offset.get(); }
 910   const PTR ptr()    const { return _ptr; }
 911 
 912   static const TypePtr* make(TYPES t, PTR ptr, Offset offset,
 913                              const TypePtr* speculative = NULL,
 914                              int inline_depth = InlineDepthBottom);
 915 
 916   // Return a 'ptr' version of this type
 917   virtual const Type *cast_to_ptr_type(PTR ptr) const;
 918 
 919   virtual intptr_t get_con() const;
 920 
 921   Offset xadd_offset(intptr_t offset) const;
 922   virtual const TypePtr *add_offset( intptr_t offset ) const;
 923   virtual bool eq(const Type *t) const;
 924   virtual int  hash() const;             // Type specific hashing
 925 
 926   virtual bool singleton(void) const;    // TRUE if type is a singleton
 927   virtual bool empty(void) const;        // TRUE if type is vacuous
 928   virtual const Type *xmeet( const Type *t ) const;
 929   virtual const Type *xmeet_helper( const Type *t ) const;
 930   Offset meet_offset(int offset) const;
 931   Offset dual_offset() const;
 932   virtual const Type *xdual() const;    // Compute dual right now.
 933 
 934   // meet, dual and join over pointer equivalence sets
 935   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
 936   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
 937 
 938   // This is textually confusing unless one recalls that
 939   // join(t) == dual()->meet(t->dual())->dual().
 940   PTR join_ptr( const PTR in_ptr ) const {
 941     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
 942   }
 943 
 944   // Speculative type helper methods.
 945   virtual const TypePtr* speculative() const { return _speculative; }
 946   int inline_depth() const                   { return _inline_depth; }
 947   virtual ciKlass* speculative_type() const;
 948   virtual ciKlass* speculative_type_not_null() const;
 949   virtual bool speculative_maybe_null() const;
 950   virtual const Type* remove_speculative() const;
 951   virtual const Type* cleanup_speculative() const;
 952   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
 953   virtual bool would_improve_ptr(bool maybe_null) const;
 954   virtual const TypePtr* with_inline_depth(int depth) const;
 955 
 956   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
 957 
 958   // Tests for relation to centerline of type lattice:
 959   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
 960   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
 961   // Convenience common pre-built types.
 962   static const TypePtr *NULL_PTR;
 963   static const TypePtr *NOTNULL;
 964   static const TypePtr *BOTTOM;
 965 #ifndef PRODUCT
 966   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
 967 #endif
 968 };
 969 
 970 //------------------------------TypeRawPtr-------------------------------------
 971 // Class of raw pointers, pointers to things other than Oops.  Examples
 972 // include the stack pointer, top of heap, card-marking area, handles, etc.
 973 class TypeRawPtr : public TypePtr {
 974 protected:
 975   TypeRawPtr(PTR ptr, address bits) : TypePtr(RawPtr,ptr,Offset(0)), _bits(bits){}
 976 public:
 977   virtual bool eq( const Type *t ) const;
 978   virtual int  hash() const;     // Type specific hashing
 979 
 980   const address _bits;          // Constant value, if applicable
 981 
 982   static const TypeRawPtr *make( PTR ptr );
 983   static const TypeRawPtr *make( address bits );
 984 
 985   // Return a 'ptr' version of this type
 986   virtual const Type *cast_to_ptr_type(PTR ptr) const;
 987 
 988   virtual intptr_t get_con() const;
 989 
 990   virtual const TypePtr *add_offset( intptr_t offset ) const;
 991 
 992   virtual const Type *xmeet( const Type *t ) const;
 993   virtual const Type *xdual() const;    // Compute dual right now.
 994   // Convenience common pre-built types.
 995   static const TypeRawPtr *BOTTOM;
 996   static const TypeRawPtr *NOTNULL;
 997 #ifndef PRODUCT
 998   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
 999 #endif
1000 };
1001 
1002 //------------------------------TypeOopPtr-------------------------------------
1003 // Some kind of oop (Java pointer), either instance or array.
1004 class TypeOopPtr : public TypePtr {
1005 protected:
1006   TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
1007              int instance_id, const TypePtr* speculative, int inline_depth);
1008 public:
1009   virtual bool eq( const Type *t ) const;
1010   virtual int  hash() const;             // Type specific hashing
1011   virtual bool singleton(void) const;    // TRUE if type is a singleton
1012   enum {
1013    InstanceTop = -1,   // undefined instance
1014    InstanceBot = 0     // any possible instance
1015   };
1016 protected:
1017 
1018   // Oop is NULL, unless this is a constant oop.
1019   ciObject*     _const_oop;   // Constant oop
1020   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
1021   ciKlass*      _klass;       // Klass object
1022   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1023   bool          _klass_is_exact;
1024   bool          _is_ptr_to_narrowoop;
1025   bool          _is_ptr_to_narrowklass;
1026   bool          _is_ptr_to_boxed_value;
1027 
1028   // If not InstanceTop or InstanceBot, indicates that this is
1029   // a particular instance of this type which is distinct.
1030   // This is the node index of the allocation node creating this instance.
1031   int           _instance_id;
1032 
1033   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1034 
1035   int dual_instance_id() const;
1036   int meet_instance_id(int uid) const;
1037 
1038   // Do not allow interface-vs.-noninterface joins to collapse to top.
1039   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1040 
1041 public:
1042   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1043   // Respects UseUniqueSubclasses.
1044   // If the klass is final, the resulting type will be exact.
1045   static const TypeOopPtr* make_from_klass(ciKlass* klass) {
1046     return make_from_klass_common(klass, true, false);
1047   }
1048   // Same as before, but will produce an exact type, even if
1049   // the klass is not final, as long as it has exactly one implementation.
1050   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
1051     return make_from_klass_common(klass, true, true);
1052   }
1053   // Same as before, but does not respects UseUniqueSubclasses.
1054   // Use this only for creating array element types.
1055   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
1056     return make_from_klass_common(klass, false, false);
1057   }
1058   // Creates a singleton type given an object.
1059   // If the object cannot be rendered as a constant,
1060   // may return a non-singleton type.
1061   // If require_constant, produce a NULL if a singleton is not possible.
1062   static const TypeOopPtr* make_from_constant(ciObject* o,
1063                                               bool require_constant = false);
1064 
1065   // Make a generic (unclassed) pointer to an oop.
1066   static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id,
1067                                 const TypePtr* speculative = NULL,
1068                                 int inline_depth = InlineDepthBottom);
1069 
1070   ciObject* const_oop()    const { return _const_oop; }
1071   virtual ciKlass* klass() const { return _klass;     }
1072   bool klass_is_exact()    const { return _klass_is_exact; }
1073 
1074   // Returns true if this pointer points at memory which contains a
1075   // compressed oop references.
1076   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1077   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1078   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1079   bool is_known_instance()       const { return _instance_id > 0; }
1080   int  instance_id()             const { return _instance_id; }
1081   bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; }
1082 
1083   virtual intptr_t get_con() const;
1084 
1085   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1086 
1087   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1088 
1089   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1090 
1091   // corresponding pointer to klass, for a given instance
1092   const TypeKlassPtr* as_klass_type() const;
1093 
1094   virtual const TypePtr *add_offset( intptr_t offset ) const;
1095 
1096   // Speculative type helper methods.
1097   virtual const Type* remove_speculative() const;
1098   virtual const Type* cleanup_speculative() const;
1099   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1100   virtual const TypePtr* with_inline_depth(int depth) const;
1101 
1102   virtual const Type *xdual() const;    // Compute dual right now.
1103   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1104   virtual const Type *xmeet_helper(const Type *t) const;
1105 
1106   // Convenience common pre-built type.
1107   static const TypeOopPtr *BOTTOM;
1108 #ifndef PRODUCT
1109   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1110 #endif
1111 };
1112 
1113 //------------------------------TypeInstPtr------------------------------------
1114 // Class of Java object pointers, pointing either to non-array Java instances
1115 // or to a Klass* (including array klasses).
1116 class TypeInstPtr : public TypeOopPtr {
1117   TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, int instance_id,
1118               const TypePtr* speculative, int inline_depth);
1119   virtual bool eq( const Type *t ) const;
1120   virtual int  hash() const;             // Type specific hashing
1121 
1122   ciSymbol*  _name;        // class name
1123 
1124  public:
1125   ciSymbol* name()         const { return _name; }
1126 
1127   bool  is_loaded() const { return _klass->is_loaded(); }
1128 
1129   // Make a pointer to a constant oop.
1130   static const TypeInstPtr *make(ciObject* o) {
1131     return make(TypePtr::Constant, o->klass(), true, o, Offset(0), InstanceBot);
1132   }
1133   // Make a pointer to a constant oop with offset.
1134   static const TypeInstPtr* make(ciObject* o, Offset offset) {
1135     return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
1136   }
1137 
1138   // Make a pointer to some value of type klass.
1139   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1140     return make(ptr, klass, false, NULL, Offset(0), InstanceBot);
1141   }
1142 
1143   // Make a pointer to some non-polymorphic value of exactly type klass.
1144   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1145     return make(ptr, klass, true, NULL, Offset(0), InstanceBot);
1146   }
1147 
1148   // Make a pointer to some value of type klass with offset.
1149   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, Offset offset) {
1150     return make(ptr, klass, false, NULL, offset, InstanceBot);
1151   }
1152 
1153   // Make a pointer to an oop.
1154   static const TypeInstPtr* make(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset,
1155                                  int instance_id = InstanceBot,
1156                                  const TypePtr* speculative = NULL,
1157                                  int inline_depth = InlineDepthBottom);
1158 
1159   /** Create constant type for a constant boxed value */
1160   const Type* get_const_boxed_value() const;
1161 
1162   // If this is a java.lang.Class constant, return the type for it or NULL.
1163   // Pass to Type::get_const_type to turn it to a type, which will usually
1164   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1165   ciType* java_mirror_type() const;
1166 
1167   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1168 
1169   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1170 
1171   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1172 
1173   virtual const TypePtr *add_offset( intptr_t offset ) const;
1174 
1175   // Speculative type helper methods.
1176   virtual const Type* remove_speculative() const;
1177   virtual const TypePtr* with_inline_depth(int depth) const;
1178 
1179   // the core of the computation of the meet of 2 types
1180   virtual const Type *xmeet_helper(const Type *t) const;
1181   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1182   virtual const Type *xdual() const;    // Compute dual right now.
1183 
1184   // Convenience common pre-built types.
1185   static const TypeInstPtr *NOTNULL;
1186   static const TypeInstPtr *BOTTOM;
1187   static const TypeInstPtr *MIRROR;
1188   static const TypeInstPtr *MARK;
1189   static const TypeInstPtr *KLASS;
1190 #ifndef PRODUCT
1191   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1192 #endif
1193 };
1194 
1195 //------------------------------TypeAryPtr-------------------------------------
1196 // Class of Java array pointers
1197 class TypeAryPtr : public TypeOopPtr {
1198   TypeAryPtr(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1199              Offset offset, Offset field_offset, int instance_id, bool is_autobox_cache,
1200              const TypePtr* speculative, int inline_depth)
1201     : TypeOopPtr(AryPtr, ptr, k, xk, o, offset, field_offset, instance_id, speculative, inline_depth),
1202     _ary(ary),
1203     _is_autobox_cache(is_autobox_cache),
1204     _field_offset(field_offset)
1205  {
1206 #ifdef ASSERT
1207     if (k != NULL) {
1208       // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1209       ciKlass* ck = compute_klass(true);
1210       if (k != ck) {
1211         this->dump(); tty->cr();
1212         tty->print(" k: ");
1213         k->print(); tty->cr();
1214         tty->print("ck: ");
1215         if (ck != NULL) ck->print();
1216         else tty->print("<NULL>");
1217         tty->cr();
1218         assert(false, "unexpected TypeAryPtr::_klass");
1219       }
1220     }
1221 #endif
1222   }
1223   virtual bool eq( const Type *t ) const;
1224   virtual int hash() const;     // Type specific hashing
1225   const TypeAry *_ary;          // Array we point into
1226   const bool     _is_autobox_cache;
1227   // For flattened value type arrays, each field of the value type in
1228   // the array has its own memory slice so we need to keep track of
1229   // which field is accessed
1230   const Offset _field_offset;
1231   Offset meet_field_offset(const Type::Offset offset) const;
1232   Offset dual_field_offset() const;
1233 
1234   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1235 
1236 public:
1237   // Accessors
1238   ciKlass* klass() const;
1239   const TypeAry* ary() const  { return _ary; }
1240   const Type*    elem() const { return _ary->_elem; }
1241   const TypeInt* size() const { return _ary->_size; }
1242   bool      is_stable() const { return _ary->_stable; }
1243 
1244   bool is_autobox_cache() const { return _is_autobox_cache; }
1245 
1246   static const TypeAryPtr* make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1247                                 Offset field_offset = Offset::bottom,
1248                                 int instance_id = InstanceBot,
1249                                 const TypePtr* speculative = NULL,
1250                                 int inline_depth = InlineDepthBottom);
1251   // Constant pointer to array
1252   static const TypeAryPtr* make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1253                                 Offset field_offset = Offset::bottom,
1254                                 int instance_id = InstanceBot,
1255                                 const TypePtr* speculative = NULL,
1256                                 int inline_depth = InlineDepthBottom,
1257                                 bool is_autobox_cache = false);
1258 
1259   // Return a 'ptr' version of this type
1260   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1261 
1262   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1263 
1264   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1265 
1266   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1267   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1268 
1269   virtual bool empty(void) const;        // TRUE if type is vacuous
1270   virtual const TypePtr *add_offset( intptr_t offset ) const;
1271 
1272   // Speculative type helper methods.
1273   virtual const Type* remove_speculative() const;
1274   virtual const TypePtr* with_inline_depth(int depth) const;
1275 
1276   // the core of the computation of the meet of 2 types
1277   virtual const Type *xmeet_helper(const Type *t) const;
1278   virtual const Type *xdual() const;    // Compute dual right now.
1279 
1280   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1281   int stable_dimension() const;
1282 
1283   const TypeAryPtr* cast_to_autobox_cache(bool cache) const;
1284 
1285   const Offset field_offset() const { return _field_offset; }
1286   const TypeAryPtr* with_field_offset(int offset) const;
1287   const TypePtr* with_field_offset_and_offset(intptr_t offset) const;
1288 
1289   // Convenience common pre-built types.
1290   static const TypeAryPtr *RANGE;
1291   static const TypeAryPtr *OOPS;
1292   static const TypeAryPtr *NARROWOOPS;
1293   static const TypeAryPtr *BYTES;
1294   static const TypeAryPtr *SHORTS;
1295   static const TypeAryPtr *CHARS;
1296   static const TypeAryPtr *INTS;
1297   static const TypeAryPtr *LONGS;
1298   static const TypeAryPtr *FLOATS;
1299   static const TypeAryPtr *DOUBLES;
1300   // selects one of the above:
1301   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1302     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1303     return _array_body_type[elem];
1304   }
1305   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1306   // sharpen the type of an int which is used as an array size
1307 #ifdef ASSERT
1308   // One type is interface, the other is oop
1309   virtual bool interface_vs_oop(const Type *t) const;
1310 #endif
1311 #ifndef PRODUCT
1312   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1313 #endif
1314 };
1315 
1316 //------------------------------TypeValueTypePtr-------------------------------------
1317 // Class of value type pointers
1318 class TypeValueTypePtr : public TypeOopPtr {
1319   TypeValueTypePtr(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth)
1320     : TypeOopPtr(ValueTypePtr, ptr, vt->value_klass(), true, o, offset, Offset::bottom, instance_id, speculative, inline_depth) {
1321     _vt = vt;
1322   }
1323 
1324   const TypeValueType* _vt;    // Value type we point to
1325 
1326 public:
1327   // Make a pointer to a value type
1328   static const TypeValueTypePtr* make(const TypeValueType* vt, PTR ptr = TypePtr::BotPTR, ciObject* o = NULL, Offset offset = Offset(0),
1329                                       int instance_id = InstanceBot, const TypePtr* speculative = NULL, int inline_depth = InlineDepthBottom);
1330   // Make a pointer to a value type
1331   static const TypeValueTypePtr* make(PTR ptr, ciValueKlass* vk, ciObject* o = NULL) { return make(TypeValueType::make(vk), ptr, o); }
1332   // Make a pointer to a constant value type
1333   static const TypeValueTypePtr* make(ciObject* o) { return make(TypePtr::Constant, o->klass()->as_value_klass(), o);  }
1334 
1335   const TypeValueType* value_type() const { return _vt; }
1336 
1337   virtual const TypePtr* add_offset(intptr_t offset) const;
1338 
1339   virtual const Type* cast_to_ptr_type(PTR ptr) const;
1340   virtual const TypeOopPtr* cast_to_instance_id(int instance_id) const;
1341 
1342   virtual bool eq(const Type* t) const;
1343   virtual int  hash() const;             // Type specific hashing
1344   virtual bool empty(void) const;        // TRUE if type is vacuous
1345 
1346   virtual const Type* xmeet_helper(const Type* t) const;
1347   virtual const Type* xdual() const;
1348 
1349   static const TypeValueTypePtr* NOTNULL;
1350 
1351 #ifndef PRODUCT
1352   virtual void dump2(Dict &d, uint depth, outputStream* st) const; // Specialized per-Type dumping
1353 #endif
1354 };
1355 
1356 //------------------------------TypeMetadataPtr-------------------------------------
1357 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1358 class TypeMetadataPtr : public TypePtr {
1359 protected:
1360   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1361   // Do not allow interface-vs.-noninterface joins to collapse to top.
1362   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1363 public:
1364   virtual bool eq( const Type *t ) const;
1365   virtual int  hash() const;             // Type specific hashing
1366   virtual bool singleton(void) const;    // TRUE if type is a singleton
1367 
1368 private:
1369   ciMetadata*   _metadata;
1370 
1371 public:
1372   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, Offset offset);
1373 
1374   static const TypeMetadataPtr* make(ciMethod* m);
1375   static const TypeMetadataPtr* make(ciMethodData* m);
1376 
1377   ciMetadata* metadata() const { return _metadata; }
1378 
1379   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1380 
1381   virtual const TypePtr *add_offset( intptr_t offset ) const;
1382 
1383   virtual const Type *xmeet( const Type *t ) const;
1384   virtual const Type *xdual() const;    // Compute dual right now.
1385 
1386   virtual intptr_t get_con() const;
1387 
1388   // Convenience common pre-built types.
1389   static const TypeMetadataPtr *BOTTOM;
1390 
1391 #ifndef PRODUCT
1392   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1393 #endif
1394 };
1395 
1396 //------------------------------TypeKlassPtr-----------------------------------
1397 // Class of Java Klass pointers
1398 class TypeKlassPtr : public TypePtr {
1399   TypeKlassPtr(PTR ptr, ciKlass* klass, Offset offset);
1400 
1401 protected:
1402   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1403  public:
1404   virtual bool eq( const Type *t ) const;
1405   virtual int hash() const;             // Type specific hashing
1406   virtual bool singleton(void) const;    // TRUE if type is a singleton
1407  private:
1408 
1409   ciKlass* _klass;
1410 
1411   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1412   bool          _klass_is_exact;
1413 
1414 public:
1415   ciKlass* klass() const { return  _klass; }
1416   bool klass_is_exact()    const { return _klass_is_exact; }
1417 
1418   bool  is_loaded() const { return klass() != NULL && klass()->is_loaded(); }
1419 
1420   // ptr to klass 'k'
1421   static const TypeKlassPtr* make(ciKlass* k) { return make( TypePtr::Constant, k, Offset(0)); }
1422   // ptr to klass 'k' with offset
1423   static const TypeKlassPtr* make(ciKlass* k, Offset offset) { return make( TypePtr::Constant, k, offset); }
1424   // ptr to klass 'k' or sub-klass
1425   static const TypeKlassPtr* make(PTR ptr, ciKlass* k, Offset offset);
1426 
1427   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1428 
1429   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1430 
1431   // corresponding pointer to instance, for a given class
1432   const TypeOopPtr* as_instance_type() const;
1433 
1434   virtual const TypePtr *add_offset( intptr_t offset ) const;
1435   virtual const Type    *xmeet( const Type *t ) const;
1436   virtual const Type    *xdual() const;      // Compute dual right now.
1437 
1438   virtual intptr_t get_con() const;
1439 
1440   // Convenience common pre-built types.
1441   static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1442   static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1443   static const TypeKlassPtr* BOTTOM;
1444 #ifndef PRODUCT
1445   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1446 #endif
1447 };
1448 
1449 class TypeNarrowPtr : public Type {
1450 protected:
1451   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1452 
1453   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
1454                                                   Type(t) {
1455     assert(ptrtype->offset() == 0 ||
1456            ptrtype->offset() == OffsetBot ||
1457            ptrtype->offset() == OffsetTop, "no real offsets");
1458   }
1459 
1460   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1461   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1462   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1463   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1464   // Do not allow interface-vs.-noninterface joins to collapse to top.
1465   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1466 public:
1467   virtual bool eq( const Type *t ) const;
1468   virtual int  hash() const;             // Type specific hashing
1469   virtual bool singleton(void) const;    // TRUE if type is a singleton
1470 
1471   virtual const Type *xmeet( const Type *t ) const;
1472   virtual const Type *xdual() const;    // Compute dual right now.
1473 
1474   virtual intptr_t get_con() const;
1475 
1476   virtual bool empty(void) const;        // TRUE if type is vacuous
1477 
1478   // returns the equivalent ptr type for this compressed pointer
1479   const TypePtr *get_ptrtype() const {
1480     return _ptrtype;
1481   }
1482 
1483 #ifndef PRODUCT
1484   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1485 #endif
1486 };
1487 
1488 //------------------------------TypeNarrowOop----------------------------------
1489 // A compressed reference to some kind of Oop.  This type wraps around
1490 // a preexisting TypeOopPtr and forwards most of it's operations to
1491 // the underlying type.  It's only real purpose is to track the
1492 // oopness of the compressed oop value when we expose the conversion
1493 // between the normal and the compressed form.
1494 class TypeNarrowOop : public TypeNarrowPtr {
1495 protected:
1496   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1497   }
1498 
1499   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1500     return t->isa_narrowoop();
1501   }
1502 
1503   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1504     return t->is_narrowoop();
1505   }
1506 
1507   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1508     return new TypeNarrowOop(t);
1509   }
1510 
1511   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1512     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1513   }
1514 
1515 public:
1516 
1517   static const TypeNarrowOop *make( const TypePtr* type);
1518 
1519   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1520     return make(TypeOopPtr::make_from_constant(con, require_constant));
1521   }
1522 
1523   static const TypeNarrowOop *BOTTOM;
1524   static const TypeNarrowOop *NULL_PTR;
1525 
1526   virtual const Type* remove_speculative() const;
1527   virtual const Type* cleanup_speculative() const;
1528 
1529 #ifndef PRODUCT
1530   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1531 #endif
1532 };
1533 
1534 //------------------------------TypeNarrowKlass----------------------------------
1535 // A compressed reference to klass pointer.  This type wraps around a
1536 // preexisting TypeKlassPtr and forwards most of it's operations to
1537 // the underlying type.
1538 class TypeNarrowKlass : public TypeNarrowPtr {
1539 protected:
1540   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1541   }
1542 
1543   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1544     return t->isa_narrowklass();
1545   }
1546 
1547   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1548     return t->is_narrowklass();
1549   }
1550 
1551   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1552     return new TypeNarrowKlass(t);
1553   }
1554 
1555   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1556     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1557   }
1558 
1559 public:
1560   static const TypeNarrowKlass *make( const TypePtr* type);
1561 
1562   // static const TypeNarrowKlass *BOTTOM;
1563   static const TypeNarrowKlass *NULL_PTR;
1564 
1565 #ifndef PRODUCT
1566   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1567 #endif
1568 };
1569 
1570 //------------------------------TypeFunc---------------------------------------
1571 // Class of Array Types
1572 class TypeFunc : public Type {
1573   TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc)
1574     : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {}
1575   virtual bool eq( const Type *t ) const;
1576   virtual int  hash() const;             // Type specific hashing
1577   virtual bool singleton(void) const;    // TRUE if type is a singleton
1578   virtual bool empty(void) const;        // TRUE if type is vacuous
1579 
1580   // Domains of inputs: value type arguments are not passed by
1581   // reference, instead each field of the value type is passed as an
1582   // argument. We maintain 2 views of the argument list here: one
1583   // based on the signature (with a value type argument as a single
1584   // slot), one based on the actual calling convention (with a value
1585   // type argument as a list of its fields).
1586   const TypeTuple* const _domain_sig;
1587   const TypeTuple* const _domain_cc;
1588   // Range of results. Similar to domains: a value type result can be
1589   // returned in registers in which case range_cc lists all fields and
1590   // is the actual calling convention.
1591   const TypeTuple* const _range_sig;
1592   const TypeTuple* const _range_cc;
1593 
1594 public:
1595   // Constants are shared among ADLC and VM
1596   enum { Control    = AdlcVMDeps::Control,
1597          I_O        = AdlcVMDeps::I_O,
1598          Memory     = AdlcVMDeps::Memory,
1599          FramePtr   = AdlcVMDeps::FramePtr,
1600          ReturnAdr  = AdlcVMDeps::ReturnAdr,
1601          Parms      = AdlcVMDeps::Parms
1602   };
1603 
1604 
1605   // Accessors:
1606   const TypeTuple* domain_sig() const { return _domain_sig; }
1607   const TypeTuple* domain_cc() const { return _domain_cc; }
1608   const TypeTuple* range_sig()  const { return _range_sig; }
1609   const TypeTuple* range_cc()  const { return _range_cc; }
1610 
1611   static const TypeFunc *make(ciMethod* method);
1612   static const TypeFunc *make(ciSignature signature, const Type* extra);
1613   static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
1614                               const TypeTuple* range_sig, const TypeTuple* range_cc);
1615   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1616 
1617   virtual const Type *xmeet( const Type *t ) const;
1618   virtual const Type *xdual() const;    // Compute dual right now.
1619 
1620   BasicType return_type() const;
1621 
1622   bool returns_value_type_as_fields() const { return range_sig() != range_cc(); }
1623 
1624 #ifndef PRODUCT
1625   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1626 #endif
1627   // Convenience common pre-built types.
1628 };
1629 
1630 //------------------------------accessors--------------------------------------
1631 inline bool Type::is_ptr_to_narrowoop() const {
1632 #ifdef _LP64
1633   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1634 #else
1635   return false;
1636 #endif
1637 }
1638 
1639 inline bool Type::is_ptr_to_narrowklass() const {
1640 #ifdef _LP64
1641   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1642 #else
1643   return false;
1644 #endif
1645 }
1646 
1647 inline float Type::getf() const {
1648   assert( _base == FloatCon, "Not a FloatCon" );
1649   return ((TypeF*)this)->_f;
1650 }
1651 
1652 inline double Type::getd() const {
1653   assert( _base == DoubleCon, "Not a DoubleCon" );
1654   return ((TypeD*)this)->_d;
1655 }
1656 
1657 inline const TypeInt *Type::is_int() const {
1658   assert( _base == Int, "Not an Int" );
1659   return (TypeInt*)this;
1660 }
1661 
1662 inline const TypeInt *Type::isa_int() const {
1663   return ( _base == Int ? (TypeInt*)this : NULL);
1664 }
1665 
1666 inline const TypeLong *Type::is_long() const {
1667   assert( _base == Long, "Not a Long" );
1668   return (TypeLong*)this;
1669 }
1670 
1671 inline const TypeLong *Type::isa_long() const {
1672   return ( _base == Long ? (TypeLong*)this : NULL);
1673 }
1674 
1675 inline const TypeF *Type::isa_float() const {
1676   return ((_base == FloatTop ||
1677            _base == FloatCon ||
1678            _base == FloatBot) ? (TypeF*)this : NULL);
1679 }
1680 
1681 inline const TypeF *Type::is_float_constant() const {
1682   assert( _base == FloatCon, "Not a Float" );
1683   return (TypeF*)this;
1684 }
1685 
1686 inline const TypeF *Type::isa_float_constant() const {
1687   return ( _base == FloatCon ? (TypeF*)this : NULL);
1688 }
1689 
1690 inline const TypeD *Type::isa_double() const {
1691   return ((_base == DoubleTop ||
1692            _base == DoubleCon ||
1693            _base == DoubleBot) ? (TypeD*)this : NULL);
1694 }
1695 
1696 inline const TypeD *Type::is_double_constant() const {
1697   assert( _base == DoubleCon, "Not a Double" );
1698   return (TypeD*)this;
1699 }
1700 
1701 inline const TypeD *Type::isa_double_constant() const {
1702   return ( _base == DoubleCon ? (TypeD*)this : NULL);
1703 }
1704 
1705 inline const TypeTuple *Type::is_tuple() const {
1706   assert( _base == Tuple, "Not a Tuple" );
1707   return (TypeTuple*)this;
1708 }
1709 
1710 inline const TypeAry *Type::is_ary() const {
1711   assert( _base == Array , "Not an Array" );
1712   return (TypeAry*)this;
1713 }
1714 
1715 inline const TypeVect *Type::is_vect() const {
1716   assert( _base >= VectorS && _base <= VectorZ, "Not a Vector" );
1717   return (TypeVect*)this;
1718 }
1719 
1720 inline const TypeVect *Type::isa_vect() const {
1721   return (_base >= VectorS && _base <= VectorZ) ? (TypeVect*)this : NULL;
1722 }
1723 
1724 inline const TypePtr *Type::is_ptr() const {
1725   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1726   assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1727   return (TypePtr*)this;
1728 }
1729 
1730 inline const TypePtr *Type::isa_ptr() const {
1731   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1732   return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1733 }
1734 
1735 inline const TypeOopPtr *Type::is_oopptr() const {
1736   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1737   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1738   return (TypeOopPtr*)this;
1739 }
1740 
1741 inline const TypeOopPtr *Type::isa_oopptr() const {
1742   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1743   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1744 }
1745 
1746 inline const TypeRawPtr *Type::isa_rawptr() const {
1747   return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1748 }
1749 
1750 inline const TypeRawPtr *Type::is_rawptr() const {
1751   assert( _base == RawPtr, "Not a raw pointer" );
1752   return (TypeRawPtr*)this;
1753 }
1754 
1755 inline const TypeInstPtr *Type::isa_instptr() const {
1756   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1757 }
1758 
1759 inline const TypeInstPtr *Type::is_instptr() const {
1760   assert( _base == InstPtr, "Not an object pointer" );
1761   return (TypeInstPtr*)this;
1762 }
1763 
1764 inline const TypeAryPtr *Type::isa_aryptr() const {
1765   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1766 }
1767 
1768 inline const TypeAryPtr *Type::is_aryptr() const {
1769   assert( _base == AryPtr, "Not an array pointer" );
1770   return (TypeAryPtr*)this;
1771 }
1772 
1773 inline const TypeValueType* Type::isa_valuetype() const {
1774   return (_base == ValueType) ? (TypeValueType*)this : NULL;
1775 }
1776 
1777 inline const TypeValueType* Type::is_valuetype() const {
1778   assert(_base == ValueType, "Not a value type");
1779   return (TypeValueType*)this;
1780 }
1781 
1782 inline const TypeValueTypePtr* Type::isa_valuetypeptr() const {
1783   return (_base == ValueTypePtr) ? (TypeValueTypePtr*)this : NULL;
1784 }
1785 
1786 inline const TypeValueTypePtr* Type::is_valuetypeptr() const {
1787   assert(_base == ValueTypePtr, "Not a value type pointer");
1788   return (TypeValueTypePtr*)this;
1789 }
1790 
1791 inline const TypeNarrowOop *Type::is_narrowoop() const {
1792   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1793   assert(_base == NarrowOop, "Not a narrow oop" ) ;
1794   return (TypeNarrowOop*)this;
1795 }
1796 
1797 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1798   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1799   return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1800 }
1801 
1802 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1803   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1804   return (TypeNarrowKlass*)this;
1805 }
1806 
1807 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1808   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1809 }
1810 
1811 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1812   // MetadataPtr is the first and CPCachePtr the last
1813   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1814   return (TypeMetadataPtr*)this;
1815 }
1816 
1817 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1818   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1819 }
1820 
1821 inline const TypeKlassPtr *Type::isa_klassptr() const {
1822   return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1823 }
1824 
1825 inline const TypeKlassPtr *Type::is_klassptr() const {
1826   assert( _base == KlassPtr, "Not a klass pointer" );
1827   return (TypeKlassPtr*)this;
1828 }
1829 
1830 inline const TypePtr* Type::make_ptr() const {
1831   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1832                               ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1833                                                        isa_ptr());
1834 }
1835 
1836 inline const TypeOopPtr* Type::make_oopptr() const {
1837   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
1838 }
1839 
1840 inline const TypeNarrowOop* Type::make_narrowoop() const {
1841   return (_base == NarrowOop) ? is_narrowoop() :
1842                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1843 }
1844 
1845 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1846   return (_base == NarrowKlass) ? is_narrowklass() :
1847                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1848 }
1849 
1850 inline bool Type::is_floatingpoint() const {
1851   if( (_base == FloatCon)  || (_base == FloatBot) ||
1852       (_base == DoubleCon) || (_base == DoubleBot) )
1853     return true;
1854   return false;
1855 }
1856 
1857 inline bool Type::is_ptr_to_boxing_obj() const {
1858   const TypeInstPtr* tp = isa_instptr();
1859   return (tp != NULL) && (tp->offset() == 0) &&
1860          tp->klass()->is_instance_klass()  &&
1861          tp->klass()->as_instance_klass()->is_box_klass();
1862 }
1863 
1864 
1865 // ===============================================================
1866 // Things that need to be 64-bits in the 64-bit build but
1867 // 32-bits in the 32-bit build.  Done this way to get full
1868 // optimization AND strong typing.
1869 #ifdef _LP64
1870 
1871 // For type queries and asserts
1872 #define is_intptr_t  is_long
1873 #define isa_intptr_t isa_long
1874 #define find_intptr_t_type find_long_type
1875 #define find_intptr_t_con  find_long_con
1876 #define TypeX        TypeLong
1877 #define Type_X       Type::Long
1878 #define TypeX_X      TypeLong::LONG
1879 #define TypeX_ZERO   TypeLong::ZERO
1880 // For 'ideal_reg' machine registers
1881 #define Op_RegX      Op_RegL
1882 // For phase->intcon variants
1883 #define MakeConX     longcon
1884 #define ConXNode     ConLNode
1885 // For array index arithmetic
1886 #define MulXNode     MulLNode
1887 #define AndXNode     AndLNode
1888 #define OrXNode      OrLNode
1889 #define CmpXNode     CmpLNode
1890 #define SubXNode     SubLNode
1891 #define LShiftXNode  LShiftLNode
1892 // For object size computation:
1893 #define AddXNode     AddLNode
1894 #define RShiftXNode  RShiftLNode
1895 // For card marks and hashcodes
1896 #define URShiftXNode URShiftLNode
1897 // UseOptoBiasInlining
1898 #define XorXNode     XorLNode
1899 #define StoreXConditionalNode StoreLConditionalNode
1900 // Opcodes
1901 #define Op_LShiftX   Op_LShiftL
1902 #define Op_AndX      Op_AndL
1903 #define Op_AddX      Op_AddL
1904 #define Op_SubX      Op_SubL
1905 #define Op_XorX      Op_XorL
1906 #define Op_URShiftX  Op_URShiftL
1907 // conversions
1908 #define ConvI2X(x)   ConvI2L(x)
1909 #define ConvL2X(x)   (x)
1910 #define ConvX2I(x)   ConvL2I(x)
1911 #define ConvX2L(x)   (x)
1912 #define ConvX2UL(x)  (x)
1913 
1914 #else
1915 
1916 // For type queries and asserts
1917 #define is_intptr_t  is_int
1918 #define isa_intptr_t isa_int
1919 #define find_intptr_t_type find_int_type
1920 #define find_intptr_t_con  find_int_con
1921 #define TypeX        TypeInt
1922 #define Type_X       Type::Int
1923 #define TypeX_X      TypeInt::INT
1924 #define TypeX_ZERO   TypeInt::ZERO
1925 // For 'ideal_reg' machine registers
1926 #define Op_RegX      Op_RegI
1927 // For phase->intcon variants
1928 #define MakeConX     intcon
1929 #define ConXNode     ConINode
1930 // For array index arithmetic
1931 #define MulXNode     MulINode
1932 #define AndXNode     AndINode
1933 #define OrXNode      OrINode
1934 #define CmpXNode     CmpINode
1935 #define SubXNode     SubINode
1936 #define LShiftXNode  LShiftINode
1937 // For object size computation:
1938 #define AddXNode     AddINode
1939 #define RShiftXNode  RShiftINode
1940 // For card marks and hashcodes
1941 #define URShiftXNode URShiftINode
1942 // UseOptoBiasInlining
1943 #define XorXNode     XorINode
1944 #define StoreXConditionalNode StoreIConditionalNode
1945 // Opcodes
1946 #define Op_LShiftX   Op_LShiftI
1947 #define Op_AndX      Op_AndI
1948 #define Op_AddX      Op_AddI
1949 #define Op_SubX      Op_SubI
1950 #define Op_XorX      Op_XorI
1951 #define Op_URShiftX  Op_URShiftI
1952 // conversions
1953 #define ConvI2X(x)   (x)
1954 #define ConvL2X(x)   ConvL2I(x)
1955 #define ConvX2I(x)   (x)
1956 #define ConvX2L(x)   ConvI2L(x)
1957 #define ConvX2UL(x)  ConvI2UL(x)
1958 
1959 #endif
1960 
1961 #endif // SHARE_VM_OPTO_TYPE_HPP