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