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