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