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