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