src/share/vm/opto/type.hpp

Tue, 10 Sep 2013 14:51:48 -0700

author
vlivanov
date
Tue, 10 Sep 2013 14:51:48 -0700
changeset 5658
edb5ab0f3fe5
parent 5614
9758d9f36299
child 5791
c9ccd7b85f20
permissions
-rw-r--r--

8001107: @Stable annotation for constant folding of lazily evaluated variables
Reviewed-by: rbackman, twisti, kvn
Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2013, 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  */
    25 #ifndef SHARE_VM_OPTO_TYPE_HPP
    26 #define SHARE_VM_OPTO_TYPE_HPP
    28 #include "libadt/port.hpp"
    29 #include "opto/adlcVMDeps.hpp"
    30 #include "runtime/handles.hpp"
    32 // Portions of code courtesy of Clifford Click
    34 // Optimization - Graph Style
    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.
    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;
    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;
    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
    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
    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.)
   102     MetadataPtr,                // Generic metadata
   103     KlassPtr,                   // Klass pointers
   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   };
   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   };
   125   // Min and max WIDEN values.
   126   enum WIDEN {
   127     WidenMin = 0,
   128     WidenMax = 3
   129   };
   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;
   141   // Dictionary of types shared among compilations.
   142   static Dict* _shared_type_dict;
   143   static TypeInfo _type_info[];
   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;
   150   // Top-level hash-table of types
   151   static Dict *type_dict() {
   152     return Compile::current()->type_dict();
   153   }
   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];
   162 protected:
   163   // Each class of type is also identified by its base.
   164   const TYPES _base;            // Enum of Types type
   166   Type( TYPES t ) : _dual(NULL),  _base(t) {} // Simple types
   167   // ~Type();                   // Use fast deallocation
   168   const Type *hashcons();       // Hash-cons the type
   170 public:
   172   inline void* operator new( size_t x ) throw() {
   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   }
   184   // Initialize the type system for a particular compilation.
   185   static void Initialize(Compile* compile);
   187   // Initialize the types shared by all compilations.
   188   static void Initialize_shared(Compile* compile);
   190   TYPES base() const {
   191     assert(_base > Bad && _base < lastype, "sanity");
   192     return _base;
   193   }
   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); }
   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; }
   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; }
   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.
   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(); }
   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;
   227 #ifdef ASSERT
   228   // One type is interface, the other is oop
   229   virtual bool interface_vs_oop(const Type *t) const;
   230 #endif
   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;
   237   bool is_ptr_to_boxing_obj() const;
   240   // Convenience access
   241   float getf() const;
   242   double getd() const;
   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
   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
   278   virtual bool      is_finite() const;           // Has a finite value
   279   virtual bool      is_nan()    const;           // Is not a number (NaN)
   281   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
   282   const TypePtr* make_ptr() const;
   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;
   288   // Returns this compressed pointer or the equivalent compressed version
   289   // of this pointer type.
   290   const TypeNarrowOop* make_narrowoop() const;
   292   // Returns this compressed klass pointer or the equivalent
   293   // compressed version of this pointer type.
   294   const TypeNarrowKlass* make_narrowklass() const;
   296   // Special test for register pressure heuristic
   297   bool is_floatingpoint() const;        // True if Float or Double base type
   299   // Do you have memory, directly or through a tuple?
   300   bool has_memory( ) const;
   302   // TRUE if type is a singleton
   303   virtual bool singleton(void) const;
   305   // TRUE if type is above the lattice centerline, and is therefore vacuous
   306   virtual bool empty(void) const;
   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;
   312   // Map ideal registers (machine types) to ideal types
   313   static const Type *mreg2type[];
   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
   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   }
   332   // Mapping to the array element's basic type.
   333   BasicType array_element_basic_type() const;
   335   // Create standard type for a ciType:
   336   static const Type* get_const_type(ciType* type);
   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   }
   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   }
   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;
   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; }
   372   // Mapping from CI type system to compiler type:
   373   static const Type* get_typeflow_type(ciType* type);
   375   static const Type* make_from_constant(ciConstant constant,
   376                                         bool require_constant = false,
   377                                         bool is_autobox_cache = false);
   379 private:
   380   // support arrays
   381   static const BasicType _basic_type[];
   382   static const Type*        _zero_type[T_CONFLICT+1];
   383   static const Type* _const_basic_type[T_CONFLICT+1];
   384 };
   386 //------------------------------TypeF------------------------------------------
   387 // Class of Float-Constant Types.
   388 class TypeF : public Type {
   389   TypeF( float f ) : Type(FloatCon), _f(f) {};
   390 public:
   391   virtual bool eq( const Type *t ) const;
   392   virtual int  hash() const;             // Type specific hashing
   393   virtual bool singleton(void) const;    // TRUE if type is a singleton
   394   virtual bool empty(void) const;        // TRUE if type is vacuous
   395 public:
   396   const float _f;               // Float constant
   398   static const TypeF *make(float f);
   400   virtual bool        is_finite() const;  // Has a finite value
   401   virtual bool        is_nan()    const;  // Is not a number (NaN)
   403   virtual const Type *xmeet( const Type *t ) const;
   404   virtual const Type *xdual() const;    // Compute dual right now.
   405   // Convenience common pre-built types.
   406   static const TypeF *ZERO; // positive zero only
   407   static const TypeF *ONE;
   408 #ifndef PRODUCT
   409   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   410 #endif
   411 };
   413 //------------------------------TypeD------------------------------------------
   414 // Class of Double-Constant Types.
   415 class TypeD : public Type {
   416   TypeD( double d ) : Type(DoubleCon), _d(d) {};
   417 public:
   418   virtual bool eq( const Type *t ) const;
   419   virtual int  hash() const;             // Type specific hashing
   420   virtual bool singleton(void) const;    // TRUE if type is a singleton
   421   virtual bool empty(void) const;        // TRUE if type is vacuous
   422 public:
   423   const double _d;              // Double constant
   425   static const TypeD *make(double d);
   427   virtual bool        is_finite() const;  // Has a finite value
   428   virtual bool        is_nan()    const;  // Is not a number (NaN)
   430   virtual const Type *xmeet( const Type *t ) const;
   431   virtual const Type *xdual() const;    // Compute dual right now.
   432   // Convenience common pre-built types.
   433   static const TypeD *ZERO; // positive zero only
   434   static const TypeD *ONE;
   435 #ifndef PRODUCT
   436   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   437 #endif
   438 };
   440 //------------------------------TypeInt----------------------------------------
   441 // Class of integer ranges, the set of integers between a lower bound and an
   442 // upper bound, inclusive.
   443 class TypeInt : public Type {
   444   TypeInt( jint lo, jint hi, int w );
   445 public:
   446   virtual bool eq( const Type *t ) const;
   447   virtual int  hash() const;             // Type specific hashing
   448   virtual bool singleton(void) const;    // TRUE if type is a singleton
   449   virtual bool empty(void) const;        // TRUE if type is vacuous
   450 public:
   451   const jint _lo, _hi;          // Lower bound, upper bound
   452   const short _widen;           // Limit on times we widen this sucker
   454   static const TypeInt *make(jint lo);
   455   // must always specify w
   456   static const TypeInt *make(jint lo, jint hi, int w);
   458   // Check for single integer
   459   int is_con() const { return _lo==_hi; }
   460   bool is_con(int i) const { return is_con() && _lo == i; }
   461   jint get_con() const { assert( is_con(), "" );  return _lo; }
   463   virtual bool        is_finite() const;  // Has a finite value
   465   virtual const Type *xmeet( const Type *t ) const;
   466   virtual const Type *xdual() const;    // Compute dual right now.
   467   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
   468   virtual const Type *narrow( const Type *t ) const;
   469   // Do not kill _widen bits.
   470   virtual const Type *filter( const Type *kills ) const;
   471   // Convenience common pre-built types.
   472   static const TypeInt *MINUS_1;
   473   static const TypeInt *ZERO;
   474   static const TypeInt *ONE;
   475   static const TypeInt *BOOL;
   476   static const TypeInt *CC;
   477   static const TypeInt *CC_LT;  // [-1]  == MINUS_1
   478   static const TypeInt *CC_GT;  // [1]   == ONE
   479   static const TypeInt *CC_EQ;  // [0]   == ZERO
   480   static const TypeInt *CC_LE;  // [-1,0]
   481   static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
   482   static const TypeInt *BYTE;
   483   static const TypeInt *UBYTE;
   484   static const TypeInt *CHAR;
   485   static const TypeInt *SHORT;
   486   static const TypeInt *POS;
   487   static const TypeInt *POS1;
   488   static const TypeInt *INT;
   489   static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
   490 #ifndef PRODUCT
   491   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   492 #endif
   493 };
   496 //------------------------------TypeLong---------------------------------------
   497 // Class of long integer ranges, the set of integers between a lower bound and
   498 // an upper bound, inclusive.
   499 class TypeLong : public Type {
   500   TypeLong( jlong lo, jlong hi, int w );
   501 public:
   502   virtual bool eq( const Type *t ) const;
   503   virtual int  hash() const;             // Type specific hashing
   504   virtual bool singleton(void) const;    // TRUE if type is a singleton
   505   virtual bool empty(void) const;        // TRUE if type is vacuous
   506 public:
   507   const jlong _lo, _hi;         // Lower bound, upper bound
   508   const short _widen;           // Limit on times we widen this sucker
   510   static const TypeLong *make(jlong lo);
   511   // must always specify w
   512   static const TypeLong *make(jlong lo, jlong hi, int w);
   514   // Check for single integer
   515   int is_con() const { return _lo==_hi; }
   516   bool is_con(int i) const { return is_con() && _lo == i; }
   517   jlong get_con() const { assert( is_con(), "" ); return _lo; }
   519   virtual bool        is_finite() const;  // Has a finite value
   521   virtual const Type *xmeet( const Type *t ) const;
   522   virtual const Type *xdual() const;    // Compute dual right now.
   523   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
   524   virtual const Type *narrow( const Type *t ) const;
   525   // Do not kill _widen bits.
   526   virtual const Type *filter( const Type *kills ) const;
   527   // Convenience common pre-built types.
   528   static const TypeLong *MINUS_1;
   529   static const TypeLong *ZERO;
   530   static const TypeLong *ONE;
   531   static const TypeLong *POS;
   532   static const TypeLong *LONG;
   533   static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
   534   static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
   535 #ifndef PRODUCT
   536   virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
   537 #endif
   538 };
   540 //------------------------------TypeTuple--------------------------------------
   541 // Class of Tuple Types, essentially type collections for function signatures
   542 // and class layouts.  It happens to also be a fast cache for the HotSpot
   543 // signature types.
   544 class TypeTuple : public Type {
   545   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
   546 public:
   547   virtual bool eq( const Type *t ) const;
   548   virtual int  hash() const;             // Type specific hashing
   549   virtual bool singleton(void) const;    // TRUE if type is a singleton
   550   virtual bool empty(void) const;        // TRUE if type is vacuous
   552 public:
   553   const uint          _cnt;              // Count of fields
   554   const Type ** const _fields;           // Array of field types
   556   // Accessors:
   557   uint cnt() const { return _cnt; }
   558   const Type* field_at(uint i) const {
   559     assert(i < _cnt, "oob");
   560     return _fields[i];
   561   }
   562   void set_field_at(uint i, const Type* t) {
   563     assert(i < _cnt, "oob");
   564     _fields[i] = t;
   565   }
   567   static const TypeTuple *make( uint cnt, const Type **fields );
   568   static const TypeTuple *make_range(ciSignature *sig);
   569   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
   571   // Subroutine call type with space allocated for argument types
   572   static const Type **fields( uint arg_cnt );
   574   virtual const Type *xmeet( const Type *t ) const;
   575   virtual const Type *xdual() const;    // Compute dual right now.
   576   // Convenience common pre-built types.
   577   static const TypeTuple *IFBOTH;
   578   static const TypeTuple *IFFALSE;
   579   static const TypeTuple *IFTRUE;
   580   static const TypeTuple *IFNEITHER;
   581   static const TypeTuple *LOOPBODY;
   582   static const TypeTuple *MEMBAR;
   583   static const TypeTuple *STORECONDITIONAL;
   584   static const TypeTuple *START_I2C;
   585   static const TypeTuple *INT_PAIR;
   586   static const TypeTuple *LONG_PAIR;
   587 #ifndef PRODUCT
   588   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
   589 #endif
   590 };
   592 //------------------------------TypeAry----------------------------------------
   593 // Class of Array Types
   594 class TypeAry : public Type {
   595   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
   596       _elem(elem), _size(size), _stable(stable) {}
   597 public:
   598   virtual bool eq( const Type *t ) const;
   599   virtual int  hash() const;             // Type specific hashing
   600   virtual bool singleton(void) const;    // TRUE if type is a singleton
   601   virtual bool empty(void) const;        // TRUE if type is vacuous
   603 private:
   604   const Type *_elem;            // Element type of array
   605   const TypeInt *_size;         // Elements in array
   606   const bool _stable;           // Are elements @Stable?
   607   friend class TypeAryPtr;
   609 public:
   610   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
   612   virtual const Type *xmeet( const Type *t ) const;
   613   virtual const Type *xdual() const;    // Compute dual right now.
   614   bool ary_must_be_exact() const;  // true if arrays of such are never generic
   615 #ifdef ASSERT
   616   // One type is interface, the other is oop
   617   virtual bool interface_vs_oop(const Type *t) const;
   618 #endif
   619 #ifndef PRODUCT
   620   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
   621 #endif
   622 };
   624 //------------------------------TypeVect---------------------------------------
   625 // Class of Vector Types
   626 class TypeVect : public Type {
   627   const Type*   _elem;  // Vector's element type
   628   const uint  _length;  // Elements in vector (power of 2)
   630 protected:
   631   TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
   632     _elem(elem), _length(length) {}
   634 public:
   635   const Type* element_type() const { return _elem; }
   636   BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
   637   uint length() const { return _length; }
   638   uint length_in_bytes() const {
   639    return _length * type2aelembytes(element_basic_type());
   640   }
   642   virtual bool eq(const Type *t) const;
   643   virtual int  hash() const;             // Type specific hashing
   644   virtual bool singleton(void) const;    // TRUE if type is a singleton
   645   virtual bool empty(void) const;        // TRUE if type is vacuous
   647   static const TypeVect *make(const BasicType elem_bt, uint length) {
   648     // Use bottom primitive type.
   649     return make(get_const_basic_type(elem_bt), length);
   650   }
   651   // Used directly by Replicate nodes to construct singleton vector.
   652   static const TypeVect *make(const Type* elem, uint length);
   654   virtual const Type *xmeet( const Type *t) const;
   655   virtual const Type *xdual() const;     // Compute dual right now.
   657   static const TypeVect *VECTS;
   658   static const TypeVect *VECTD;
   659   static const TypeVect *VECTX;
   660   static const TypeVect *VECTY;
   662 #ifndef PRODUCT
   663   virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
   664 #endif
   665 };
   667 class TypeVectS : public TypeVect {
   668   friend class TypeVect;
   669   TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
   670 };
   672 class TypeVectD : public TypeVect {
   673   friend class TypeVect;
   674   TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
   675 };
   677 class TypeVectX : public TypeVect {
   678   friend class TypeVect;
   679   TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
   680 };
   682 class TypeVectY : public TypeVect {
   683   friend class TypeVect;
   684   TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
   685 };
   687 //------------------------------TypePtr----------------------------------------
   688 // Class of machine Pointer Types: raw data, instances or arrays.
   689 // If the _base enum is AnyPtr, then this refers to all of the above.
   690 // Otherwise the _base will indicate which subset of pointers is affected,
   691 // and the class will be inherited from.
   692 class TypePtr : public Type {
   693   friend class TypeNarrowPtr;
   694 public:
   695   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
   696 protected:
   697   TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
   698   virtual bool eq( const Type *t ) const;
   699   virtual int  hash() const;             // Type specific hashing
   700   static const PTR ptr_meet[lastPTR][lastPTR];
   701   static const PTR ptr_dual[lastPTR];
   702   static const char * const ptr_msg[lastPTR];
   704 public:
   705   const int _offset;            // Offset into oop, with TOP & BOT
   706   const PTR _ptr;               // Pointer equivalence class
   708   const int offset() const { return _offset; }
   709   const PTR ptr()    const { return _ptr; }
   711   static const TypePtr *make( TYPES t, PTR ptr, int offset );
   713   // Return a 'ptr' version of this type
   714   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   716   virtual intptr_t get_con() const;
   718   int xadd_offset( intptr_t offset ) const;
   719   virtual const TypePtr *add_offset( intptr_t offset ) const;
   721   virtual bool singleton(void) const;    // TRUE if type is a singleton
   722   virtual bool empty(void) const;        // TRUE if type is vacuous
   723   virtual const Type *xmeet( const Type *t ) const;
   724   int meet_offset( int offset ) const;
   725   int dual_offset( ) const;
   726   virtual const Type *xdual() const;    // Compute dual right now.
   728   // meet, dual and join over pointer equivalence sets
   729   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
   730   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
   732   // This is textually confusing unless one recalls that
   733   // join(t) == dual()->meet(t->dual())->dual().
   734   PTR join_ptr( const PTR in_ptr ) const {
   735     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
   736   }
   738   // Tests for relation to centerline of type lattice:
   739   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
   740   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
   741   // Convenience common pre-built types.
   742   static const TypePtr *NULL_PTR;
   743   static const TypePtr *NOTNULL;
   744   static const TypePtr *BOTTOM;
   745 #ifndef PRODUCT
   746   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
   747 #endif
   748 };
   750 //------------------------------TypeRawPtr-------------------------------------
   751 // Class of raw pointers, pointers to things other than Oops.  Examples
   752 // include the stack pointer, top of heap, card-marking area, handles, etc.
   753 class TypeRawPtr : public TypePtr {
   754 protected:
   755   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
   756 public:
   757   virtual bool eq( const Type *t ) const;
   758   virtual int  hash() const;     // Type specific hashing
   760   const address _bits;          // Constant value, if applicable
   762   static const TypeRawPtr *make( PTR ptr );
   763   static const TypeRawPtr *make( address bits );
   765   // Return a 'ptr' version of this type
   766   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   768   virtual intptr_t get_con() const;
   770   virtual const TypePtr *add_offset( intptr_t offset ) const;
   772   virtual const Type *xmeet( const Type *t ) const;
   773   virtual const Type *xdual() const;    // Compute dual right now.
   774   // Convenience common pre-built types.
   775   static const TypeRawPtr *BOTTOM;
   776   static const TypeRawPtr *NOTNULL;
   777 #ifndef PRODUCT
   778   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
   779 #endif
   780 };
   782 //------------------------------TypeOopPtr-------------------------------------
   783 // Some kind of oop (Java pointer), either klass or instance or array.
   784 class TypeOopPtr : public TypePtr {
   785 protected:
   786   TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
   787 public:
   788   virtual bool eq( const Type *t ) const;
   789   virtual int  hash() const;             // Type specific hashing
   790   virtual bool singleton(void) const;    // TRUE if type is a singleton
   791   enum {
   792    InstanceTop = -1,   // undefined instance
   793    InstanceBot = 0     // any possible instance
   794   };
   795 protected:
   797   // Oop is NULL, unless this is a constant oop.
   798   ciObject*     _const_oop;   // Constant oop
   799   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
   800   ciKlass*      _klass;       // Klass object
   801   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
   802   bool          _klass_is_exact;
   803   bool          _is_ptr_to_narrowoop;
   804   bool          _is_ptr_to_narrowklass;
   805   bool          _is_ptr_to_boxed_value;
   807   // If not InstanceTop or InstanceBot, indicates that this is
   808   // a particular instance of this type which is distinct.
   809   // This is the the node index of the allocation node creating this instance.
   810   int           _instance_id;
   812   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
   814   int dual_instance_id() const;
   815   int meet_instance_id(int uid) const;
   817 public:
   818   // Creates a type given a klass. Correctly handles multi-dimensional arrays
   819   // Respects UseUniqueSubclasses.
   820   // If the klass is final, the resulting type will be exact.
   821   static const TypeOopPtr* make_from_klass(ciKlass* klass) {
   822     return make_from_klass_common(klass, true, false);
   823   }
   824   // Same as before, but will produce an exact type, even if
   825   // the klass is not final, as long as it has exactly one implementation.
   826   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
   827     return make_from_klass_common(klass, true, true);
   828   }
   829   // Same as before, but does not respects UseUniqueSubclasses.
   830   // Use this only for creating array element types.
   831   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
   832     return make_from_klass_common(klass, false, false);
   833   }
   834   // Creates a singleton type given an object.
   835   // If the object cannot be rendered as a constant,
   836   // may return a non-singleton type.
   837   // If require_constant, produce a NULL if a singleton is not possible.
   838   static const TypeOopPtr* make_from_constant(ciObject* o,
   839                                               bool require_constant = false,
   840                                               bool not_null_elements = false);
   842   // Make a generic (unclassed) pointer to an oop.
   843   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id);
   845   ciObject* const_oop()    const { return _const_oop; }
   846   virtual ciKlass* klass() const { return _klass;     }
   847   bool klass_is_exact()    const { return _klass_is_exact; }
   849   // Returns true if this pointer points at memory which contains a
   850   // compressed oop references.
   851   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
   852   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
   853   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
   854   bool is_known_instance()       const { return _instance_id > 0; }
   855   int  instance_id()             const { return _instance_id; }
   856   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
   858   virtual intptr_t get_con() const;
   860   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   862   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
   864   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
   866   // corresponding pointer to klass, for a given instance
   867   const TypeKlassPtr* as_klass_type() const;
   869   virtual const TypePtr *add_offset( intptr_t offset ) const;
   871   virtual const Type *xmeet( const Type *t ) const;
   872   virtual const Type *xdual() const;    // Compute dual right now.
   874   // Do not allow interface-vs.-noninterface joins to collapse to top.
   875   virtual const Type *filter( const Type *kills ) const;
   877   // Convenience common pre-built type.
   878   static const TypeOopPtr *BOTTOM;
   879 #ifndef PRODUCT
   880   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   881 #endif
   882 };
   884 //------------------------------TypeInstPtr------------------------------------
   885 // Class of Java object pointers, pointing either to non-array Java instances
   886 // or to a Klass* (including array klasses).
   887 class TypeInstPtr : public TypeOopPtr {
   888   TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
   889   virtual bool eq( const Type *t ) const;
   890   virtual int  hash() const;             // Type specific hashing
   892   ciSymbol*  _name;        // class name
   894  public:
   895   ciSymbol* name()         const { return _name; }
   897   bool  is_loaded() const { return _klass->is_loaded(); }
   899   // Make a pointer to a constant oop.
   900   static const TypeInstPtr *make(ciObject* o) {
   901     return make(TypePtr::Constant, o->klass(), true, o, 0);
   902   }
   903   // Make a pointer to a constant oop with offset.
   904   static const TypeInstPtr *make(ciObject* o, int offset) {
   905     return make(TypePtr::Constant, o->klass(), true, o, offset);
   906   }
   908   // Make a pointer to some value of type klass.
   909   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
   910     return make(ptr, klass, false, NULL, 0);
   911   }
   913   // Make a pointer to some non-polymorphic value of exactly type klass.
   914   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
   915     return make(ptr, klass, true, NULL, 0);
   916   }
   918   // Make a pointer to some value of type klass with offset.
   919   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
   920     return make(ptr, klass, false, NULL, offset);
   921   }
   923   // Make a pointer to an oop.
   924   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot );
   926   /** Create constant type for a constant boxed value */
   927   const Type* get_const_boxed_value() const;
   929   // If this is a java.lang.Class constant, return the type for it or NULL.
   930   // Pass to Type::get_const_type to turn it to a type, which will usually
   931   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
   932   ciType* java_mirror_type() const;
   934   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   936   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
   938   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
   940   virtual const TypePtr *add_offset( intptr_t offset ) const;
   942   virtual const Type *xmeet( const Type *t ) const;
   943   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
   944   virtual const Type *xdual() const;    // Compute dual right now.
   946   // Convenience common pre-built types.
   947   static const TypeInstPtr *NOTNULL;
   948   static const TypeInstPtr *BOTTOM;
   949   static const TypeInstPtr *MIRROR;
   950   static const TypeInstPtr *MARK;
   951   static const TypeInstPtr *KLASS;
   952 #ifndef PRODUCT
   953   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
   954 #endif
   955 };
   957 //------------------------------TypeAryPtr-------------------------------------
   958 // Class of Java array pointers
   959 class TypeAryPtr : public TypeOopPtr {
   960   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
   961               int offset, int instance_id, bool is_autobox_cache )
   962   : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id),
   963     _ary(ary),
   964     _is_autobox_cache(is_autobox_cache)
   965  {
   966 #ifdef ASSERT
   967     if (k != NULL) {
   968       // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
   969       ciKlass* ck = compute_klass(true);
   970       if (k != ck) {
   971         this->dump(); tty->cr();
   972         tty->print(" k: ");
   973         k->print(); tty->cr();
   974         tty->print("ck: ");
   975         if (ck != NULL) ck->print();
   976         else tty->print("<NULL>");
   977         tty->cr();
   978         assert(false, "unexpected TypeAryPtr::_klass");
   979       }
   980     }
   981 #endif
   982   }
   983   virtual bool eq( const Type *t ) const;
   984   virtual int hash() const;     // Type specific hashing
   985   const TypeAry *_ary;          // Array we point into
   986   const bool     _is_autobox_cache;
   988   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
   990 public:
   991   // Accessors
   992   ciKlass* klass() const;
   993   const TypeAry* ary() const  { return _ary; }
   994   const Type*    elem() const { return _ary->_elem; }
   995   const TypeInt* size() const { return _ary->_size; }
   996   bool      is_stable() const { return _ary->_stable; }
   998   bool is_autobox_cache() const { return _is_autobox_cache; }
  1000   static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
  1001   // Constant pointer to array
  1002   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);
  1004   // Return a 'ptr' version of this type
  1005   virtual const Type *cast_to_ptr_type(PTR ptr) const;
  1007   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
  1009   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
  1011   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
  1012   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
  1014   virtual bool empty(void) const;        // TRUE if type is vacuous
  1015   virtual const TypePtr *add_offset( intptr_t offset ) const;
  1017   virtual const Type *xmeet( const Type *t ) const;
  1018   virtual const Type *xdual() const;    // Compute dual right now.
  1020   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
  1021   int stable_dimension() const;
  1023   // Convenience common pre-built types.
  1024   static const TypeAryPtr *RANGE;
  1025   static const TypeAryPtr *OOPS;
  1026   static const TypeAryPtr *NARROWOOPS;
  1027   static const TypeAryPtr *BYTES;
  1028   static const TypeAryPtr *SHORTS;
  1029   static const TypeAryPtr *CHARS;
  1030   static const TypeAryPtr *INTS;
  1031   static const TypeAryPtr *LONGS;
  1032   static const TypeAryPtr *FLOATS;
  1033   static const TypeAryPtr *DOUBLES;
  1034   // selects one of the above:
  1035   static const TypeAryPtr *get_array_body_type(BasicType elem) {
  1036     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
  1037     return _array_body_type[elem];
  1039   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
  1040   // sharpen the type of an int which is used as an array size
  1041 #ifdef ASSERT
  1042   // One type is interface, the other is oop
  1043   virtual bool interface_vs_oop(const Type *t) const;
  1044 #endif
  1045 #ifndef PRODUCT
  1046   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
  1047 #endif
  1048 };
  1050 //------------------------------TypeMetadataPtr-------------------------------------
  1051 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
  1052 class TypeMetadataPtr : public TypePtr {
  1053 protected:
  1054   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
  1055 public:
  1056   virtual bool eq( const Type *t ) const;
  1057   virtual int  hash() const;             // Type specific hashing
  1058   virtual bool singleton(void) const;    // TRUE if type is a singleton
  1060 private:
  1061   ciMetadata*   _metadata;
  1063 public:
  1064   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
  1066   static const TypeMetadataPtr* make(ciMethod* m);
  1067   static const TypeMetadataPtr* make(ciMethodData* m);
  1069   ciMetadata* metadata() const { return _metadata; }
  1071   virtual const Type *cast_to_ptr_type(PTR ptr) const;
  1073   virtual const TypePtr *add_offset( intptr_t offset ) const;
  1075   virtual const Type *xmeet( const Type *t ) const;
  1076   virtual const Type *xdual() const;    // Compute dual right now.
  1078   virtual intptr_t get_con() const;
  1080   // Do not allow interface-vs.-noninterface joins to collapse to top.
  1081   virtual const Type *filter( const Type *kills ) const;
  1083   // Convenience common pre-built types.
  1084   static const TypeMetadataPtr *BOTTOM;
  1086 #ifndef PRODUCT
  1087   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
  1088 #endif
  1089 };
  1091 //------------------------------TypeKlassPtr-----------------------------------
  1092 // Class of Java Klass pointers
  1093 class TypeKlassPtr : public TypePtr {
  1094   TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
  1096  public:
  1097   virtual bool eq( const Type *t ) const;
  1098   virtual int hash() const;             // Type specific hashing
  1099   virtual bool singleton(void) const;    // TRUE if type is a singleton
  1100  private:
  1102   static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
  1104   ciKlass* _klass;
  1106   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
  1107   bool          _klass_is_exact;
  1109 public:
  1110   ciSymbol* name()  const { return klass()->name(); }
  1112   ciKlass* klass() const { return  _klass; }
  1113   bool klass_is_exact()    const { return _klass_is_exact; }
  1115   bool  is_loaded() const { return klass()->is_loaded(); }
  1117   // Creates a type given a klass. Correctly handles multi-dimensional arrays
  1118   // Respects UseUniqueSubclasses.
  1119   // If the klass is final, the resulting type will be exact.
  1120   static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
  1121     return make_from_klass_common(klass, true, false);
  1123   // Same as before, but will produce an exact type, even if
  1124   // the klass is not final, as long as it has exactly one implementation.
  1125   static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
  1126     return make_from_klass_common(klass, true, true);
  1128   // Same as before, but does not respects UseUniqueSubclasses.
  1129   // Use this only for creating array element types.
  1130   static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
  1131     return make_from_klass_common(klass, false, false);
  1134   // Make a generic (unclassed) pointer to metadata.
  1135   static const TypeKlassPtr* make(PTR ptr, int offset);
  1137   // ptr to klass 'k'
  1138   static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
  1139   // ptr to klass 'k' with offset
  1140   static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
  1141   // ptr to klass 'k' or sub-klass
  1142   static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
  1144   virtual const Type *cast_to_ptr_type(PTR ptr) const;
  1146   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
  1148   // corresponding pointer to instance, for a given class
  1149   const TypeOopPtr* as_instance_type() const;
  1151   virtual const TypePtr *add_offset( intptr_t offset ) const;
  1152   virtual const Type    *xmeet( const Type *t ) const;
  1153   virtual const Type    *xdual() const;      // Compute dual right now.
  1155   virtual intptr_t get_con() const;
  1157   // Convenience common pre-built types.
  1158   static const TypeKlassPtr* OBJECT; // Not-null object klass or below
  1159   static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
  1160 #ifndef PRODUCT
  1161   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
  1162 #endif
  1163 };
  1165 class TypeNarrowPtr : public Type {
  1166 protected:
  1167   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
  1169   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
  1170                                                   Type(t) {
  1171     assert(ptrtype->offset() == 0 ||
  1172            ptrtype->offset() == OffsetBot ||
  1173            ptrtype->offset() == OffsetTop, "no real offsets");
  1176   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
  1177   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
  1178   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
  1179   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
  1180 public:
  1181   virtual bool eq( const Type *t ) const;
  1182   virtual int  hash() const;             // Type specific hashing
  1183   virtual bool singleton(void) const;    // TRUE if type is a singleton
  1185   virtual const Type *xmeet( const Type *t ) const;
  1186   virtual const Type *xdual() const;    // Compute dual right now.
  1188   virtual intptr_t get_con() const;
  1190   // Do not allow interface-vs.-noninterface joins to collapse to top.
  1191   virtual const Type *filter( const Type *kills ) const;
  1193   virtual bool empty(void) const;        // TRUE if type is vacuous
  1195   // returns the equivalent ptr type for this compressed pointer
  1196   const TypePtr *get_ptrtype() const {
  1197     return _ptrtype;
  1200 #ifndef PRODUCT
  1201   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
  1202 #endif
  1203 };
  1205 //------------------------------TypeNarrowOop----------------------------------
  1206 // A compressed reference to some kind of Oop.  This type wraps around
  1207 // a preexisting TypeOopPtr and forwards most of it's operations to
  1208 // the underlying type.  It's only real purpose is to track the
  1209 // oopness of the compressed oop value when we expose the conversion
  1210 // between the normal and the compressed form.
  1211 class TypeNarrowOop : public TypeNarrowPtr {
  1212 protected:
  1213   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
  1216   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
  1217     return t->isa_narrowoop();
  1220   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
  1221     return t->is_narrowoop();
  1224   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
  1225     return new TypeNarrowOop(t);
  1228   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
  1229     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
  1232 public:
  1234   static const TypeNarrowOop *make( const TypePtr* type);
  1236   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
  1237     return make(TypeOopPtr::make_from_constant(con, require_constant));
  1240   static const TypeNarrowOop *BOTTOM;
  1241   static const TypeNarrowOop *NULL_PTR;
  1243 #ifndef PRODUCT
  1244   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
  1245 #endif
  1246 };
  1248 //------------------------------TypeNarrowKlass----------------------------------
  1249 // A compressed reference to klass pointer.  This type wraps around a
  1250 // preexisting TypeKlassPtr and forwards most of it's operations to
  1251 // the underlying type.
  1252 class TypeNarrowKlass : public TypeNarrowPtr {
  1253 protected:
  1254   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
  1257   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
  1258     return t->isa_narrowklass();
  1261   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
  1262     return t->is_narrowklass();
  1265   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
  1266     return new TypeNarrowKlass(t);
  1269   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
  1270     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
  1273 public:
  1274   static const TypeNarrowKlass *make( const TypePtr* type);
  1276   // static const TypeNarrowKlass *BOTTOM;
  1277   static const TypeNarrowKlass *NULL_PTR;
  1279 #ifndef PRODUCT
  1280   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
  1281 #endif
  1282 };
  1284 //------------------------------TypeFunc---------------------------------------
  1285 // Class of Array Types
  1286 class TypeFunc : public Type {
  1287   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}
  1288   virtual bool eq( const Type *t ) const;
  1289   virtual int  hash() const;             // Type specific hashing
  1290   virtual bool singleton(void) const;    // TRUE if type is a singleton
  1291   virtual bool empty(void) const;        // TRUE if type is vacuous
  1292 public:
  1293   // Constants are shared among ADLC and VM
  1294   enum { Control    = AdlcVMDeps::Control,
  1295          I_O        = AdlcVMDeps::I_O,
  1296          Memory     = AdlcVMDeps::Memory,
  1297          FramePtr   = AdlcVMDeps::FramePtr,
  1298          ReturnAdr  = AdlcVMDeps::ReturnAdr,
  1299          Parms      = AdlcVMDeps::Parms
  1300   };
  1302   const TypeTuple* const _domain;     // Domain of inputs
  1303   const TypeTuple* const _range;      // Range of results
  1305   // Accessors:
  1306   const TypeTuple* domain() const { return _domain; }
  1307   const TypeTuple* range()  const { return _range; }
  1309   static const TypeFunc *make(ciMethod* method);
  1310   static const TypeFunc *make(ciSignature signature, const Type* extra);
  1311   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
  1313   virtual const Type *xmeet( const Type *t ) const;
  1314   virtual const Type *xdual() const;    // Compute dual right now.
  1316   BasicType return_type() const;
  1318 #ifndef PRODUCT
  1319   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
  1320 #endif
  1321   // Convenience common pre-built types.
  1322 };
  1324 //------------------------------accessors--------------------------------------
  1325 inline bool Type::is_ptr_to_narrowoop() const {
  1326 #ifdef _LP64
  1327   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
  1328 #else
  1329   return false;
  1330 #endif
  1333 inline bool Type::is_ptr_to_narrowklass() const {
  1334 #ifdef _LP64
  1335   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
  1336 #else
  1337   return false;
  1338 #endif
  1341 inline float Type::getf() const {
  1342   assert( _base == FloatCon, "Not a FloatCon" );
  1343   return ((TypeF*)this)->_f;
  1346 inline double Type::getd() const {
  1347   assert( _base == DoubleCon, "Not a DoubleCon" );
  1348   return ((TypeD*)this)->_d;
  1351 inline const TypeInt *Type::is_int() const {
  1352   assert( _base == Int, "Not an Int" );
  1353   return (TypeInt*)this;
  1356 inline const TypeInt *Type::isa_int() const {
  1357   return ( _base == Int ? (TypeInt*)this : NULL);
  1360 inline const TypeLong *Type::is_long() const {
  1361   assert( _base == Long, "Not a Long" );
  1362   return (TypeLong*)this;
  1365 inline const TypeLong *Type::isa_long() const {
  1366   return ( _base == Long ? (TypeLong*)this : NULL);
  1369 inline const TypeF *Type::isa_float() const {
  1370   return ((_base == FloatTop ||
  1371            _base == FloatCon ||
  1372            _base == FloatBot) ? (TypeF*)this : NULL);
  1375 inline const TypeF *Type::is_float_constant() const {
  1376   assert( _base == FloatCon, "Not a Float" );
  1377   return (TypeF*)this;
  1380 inline const TypeF *Type::isa_float_constant() const {
  1381   return ( _base == FloatCon ? (TypeF*)this : NULL);
  1384 inline const TypeD *Type::isa_double() const {
  1385   return ((_base == DoubleTop ||
  1386            _base == DoubleCon ||
  1387            _base == DoubleBot) ? (TypeD*)this : NULL);
  1390 inline const TypeD *Type::is_double_constant() const {
  1391   assert( _base == DoubleCon, "Not a Double" );
  1392   return (TypeD*)this;
  1395 inline const TypeD *Type::isa_double_constant() const {
  1396   return ( _base == DoubleCon ? (TypeD*)this : NULL);
  1399 inline const TypeTuple *Type::is_tuple() const {
  1400   assert( _base == Tuple, "Not a Tuple" );
  1401   return (TypeTuple*)this;
  1404 inline const TypeAry *Type::is_ary() const {
  1405   assert( _base == Array , "Not an Array" );
  1406   return (TypeAry*)this;
  1409 inline const TypeVect *Type::is_vect() const {
  1410   assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
  1411   return (TypeVect*)this;
  1414 inline const TypeVect *Type::isa_vect() const {
  1415   return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
  1418 inline const TypePtr *Type::is_ptr() const {
  1419   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
  1420   assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
  1421   return (TypePtr*)this;
  1424 inline const TypePtr *Type::isa_ptr() const {
  1425   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
  1426   return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
  1429 inline const TypeOopPtr *Type::is_oopptr() const {
  1430   // OopPtr is the first and KlassPtr the last, with no non-oops between.
  1431   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
  1432   return (TypeOopPtr*)this;
  1435 inline const TypeOopPtr *Type::isa_oopptr() const {
  1436   // OopPtr is the first and KlassPtr the last, with no non-oops between.
  1437   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
  1440 inline const TypeRawPtr *Type::isa_rawptr() const {
  1441   return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
  1444 inline const TypeRawPtr *Type::is_rawptr() const {
  1445   assert( _base == RawPtr, "Not a raw pointer" );
  1446   return (TypeRawPtr*)this;
  1449 inline const TypeInstPtr *Type::isa_instptr() const {
  1450   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
  1453 inline const TypeInstPtr *Type::is_instptr() const {
  1454   assert( _base == InstPtr, "Not an object pointer" );
  1455   return (TypeInstPtr*)this;
  1458 inline const TypeAryPtr *Type::isa_aryptr() const {
  1459   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
  1462 inline const TypeAryPtr *Type::is_aryptr() const {
  1463   assert( _base == AryPtr, "Not an array pointer" );
  1464   return (TypeAryPtr*)this;
  1467 inline const TypeNarrowOop *Type::is_narrowoop() const {
  1468   // OopPtr is the first and KlassPtr the last, with no non-oops between.
  1469   assert(_base == NarrowOop, "Not a narrow oop" ) ;
  1470   return (TypeNarrowOop*)this;
  1473 inline const TypeNarrowOop *Type::isa_narrowoop() const {
  1474   // OopPtr is the first and KlassPtr the last, with no non-oops between.
  1475   return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
  1478 inline const TypeNarrowKlass *Type::is_narrowklass() const {
  1479   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
  1480   return (TypeNarrowKlass*)this;
  1483 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
  1484   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
  1487 inline const TypeMetadataPtr *Type::is_metadataptr() const {
  1488   // MetadataPtr is the first and CPCachePtr the last
  1489   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
  1490   return (TypeMetadataPtr*)this;
  1493 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
  1494   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
  1497 inline const TypeKlassPtr *Type::isa_klassptr() const {
  1498   return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
  1501 inline const TypeKlassPtr *Type::is_klassptr() const {
  1502   assert( _base == KlassPtr, "Not a klass pointer" );
  1503   return (TypeKlassPtr*)this;
  1506 inline const TypePtr* Type::make_ptr() const {
  1507   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
  1508     ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
  1509      (isa_ptr() ? is_ptr() : NULL));
  1512 inline const TypeOopPtr* Type::make_oopptr() const {
  1513   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
  1516 inline const TypeNarrowOop* Type::make_narrowoop() const {
  1517   return (_base == NarrowOop) ? is_narrowoop() :
  1518                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
  1521 inline const TypeNarrowKlass* Type::make_narrowklass() const {
  1522   return (_base == NarrowKlass) ? is_narrowklass() :
  1523                                 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
  1526 inline bool Type::is_floatingpoint() const {
  1527   if( (_base == FloatCon)  || (_base == FloatBot) ||
  1528       (_base == DoubleCon) || (_base == DoubleBot) )
  1529     return true;
  1530   return false;
  1533 inline bool Type::is_ptr_to_boxing_obj() const {
  1534   const TypeInstPtr* tp = isa_instptr();
  1535   return (tp != NULL) && (tp->offset() == 0) &&
  1536          tp->klass()->is_instance_klass()  &&
  1537          tp->klass()->as_instance_klass()->is_box_klass();
  1541 // ===============================================================
  1542 // Things that need to be 64-bits in the 64-bit build but
  1543 // 32-bits in the 32-bit build.  Done this way to get full
  1544 // optimization AND strong typing.
  1545 #ifdef _LP64
  1547 // For type queries and asserts
  1548 #define is_intptr_t  is_long
  1549 #define isa_intptr_t isa_long
  1550 #define find_intptr_t_type find_long_type
  1551 #define find_intptr_t_con  find_long_con
  1552 #define TypeX        TypeLong
  1553 #define Type_X       Type::Long
  1554 #define TypeX_X      TypeLong::LONG
  1555 #define TypeX_ZERO   TypeLong::ZERO
  1556 // For 'ideal_reg' machine registers
  1557 #define Op_RegX      Op_RegL
  1558 // For phase->intcon variants
  1559 #define MakeConX     longcon
  1560 #define ConXNode     ConLNode
  1561 // For array index arithmetic
  1562 #define MulXNode     MulLNode
  1563 #define AndXNode     AndLNode
  1564 #define OrXNode      OrLNode
  1565 #define CmpXNode     CmpLNode
  1566 #define SubXNode     SubLNode
  1567 #define LShiftXNode  LShiftLNode
  1568 // For object size computation:
  1569 #define AddXNode     AddLNode
  1570 #define RShiftXNode  RShiftLNode
  1571 // For card marks and hashcodes
  1572 #define URShiftXNode URShiftLNode
  1573 // UseOptoBiasInlining
  1574 #define XorXNode     XorLNode
  1575 #define StoreXConditionalNode StoreLConditionalNode
  1576 // Opcodes
  1577 #define Op_LShiftX   Op_LShiftL
  1578 #define Op_AndX      Op_AndL
  1579 #define Op_AddX      Op_AddL
  1580 #define Op_SubX      Op_SubL
  1581 #define Op_XorX      Op_XorL
  1582 #define Op_URShiftX  Op_URShiftL
  1583 // conversions
  1584 #define ConvI2X(x)   ConvI2L(x)
  1585 #define ConvL2X(x)   (x)
  1586 #define ConvX2I(x)   ConvL2I(x)
  1587 #define ConvX2L(x)   (x)
  1589 #else
  1591 // For type queries and asserts
  1592 #define is_intptr_t  is_int
  1593 #define isa_intptr_t isa_int
  1594 #define find_intptr_t_type find_int_type
  1595 #define find_intptr_t_con  find_int_con
  1596 #define TypeX        TypeInt
  1597 #define Type_X       Type::Int
  1598 #define TypeX_X      TypeInt::INT
  1599 #define TypeX_ZERO   TypeInt::ZERO
  1600 // For 'ideal_reg' machine registers
  1601 #define Op_RegX      Op_RegI
  1602 // For phase->intcon variants
  1603 #define MakeConX     intcon
  1604 #define ConXNode     ConINode
  1605 // For array index arithmetic
  1606 #define MulXNode     MulINode
  1607 #define AndXNode     AndINode
  1608 #define OrXNode      OrINode
  1609 #define CmpXNode     CmpINode
  1610 #define SubXNode     SubINode
  1611 #define LShiftXNode  LShiftINode
  1612 // For object size computation:
  1613 #define AddXNode     AddINode
  1614 #define RShiftXNode  RShiftINode
  1615 // For card marks and hashcodes
  1616 #define URShiftXNode URShiftINode
  1617 // UseOptoBiasInlining
  1618 #define XorXNode     XorINode
  1619 #define StoreXConditionalNode StoreIConditionalNode
  1620 // Opcodes
  1621 #define Op_LShiftX   Op_LShiftI
  1622 #define Op_AndX      Op_AndI
  1623 #define Op_AddX      Op_AddI
  1624 #define Op_SubX      Op_SubI
  1625 #define Op_XorX      Op_XorI
  1626 #define Op_URShiftX  Op_URShiftI
  1627 // conversions
  1628 #define ConvI2X(x)   (x)
  1629 #define ConvL2X(x)   ConvL2I(x)
  1630 #define ConvX2I(x)   (x)
  1631 #define ConvX2L(x)   ConvI2L(x)
  1633 #endif
  1635 #endif // SHARE_VM_OPTO_TYPE_HPP

mercurial