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