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