src/share/vm/opto/type.hpp

Wed, 05 Dec 2007 09:01:00 -0800

author
never
date
Wed, 05 Dec 2007 09:01:00 -0800
changeset 452
ff5961f4c095
parent 435
a61af66fc99e
child 499
b8f5ba577b02
permissions
-rw-r--r--

6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
Reviewed-by: kvn, rasbold

     1 /*
     2  * Copyright 1997-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // Portions of code courtesy of Clifford Click
    27 // Optimization - Graph Style
    30 // This class defines a Type lattice.  The lattice is used in the constant
    31 // propagation algorithms, and for some type-checking of the iloc code.
    32 // Basic types include RSD's (lower bound, upper bound, stride for integers),
    33 // float & double precision constants, sets of data-labels and code-labels.
    34 // The complete lattice is described below.  Subtypes have no relationship to
    35 // up or down in the lattice; that is entirely determined by the behavior of
    36 // the MEET/JOIN functions.
    38 class Dict;
    39 class Type;
    40 class   TypeD;
    41 class   TypeF;
    42 class   TypeInt;
    43 class   TypeLong;
    44 class   TypeAry;
    45 class   TypeTuple;
    46 class   TypePtr;
    47 class     TypeRawPtr;
    48 class     TypeOopPtr;
    49 class       TypeInstPtr;
    50 class       TypeAryPtr;
    51 class       TypeKlassPtr;
    53 //------------------------------Type-------------------------------------------
    54 // Basic Type object, represents a set of primitive Values.
    55 // Types are hash-cons'd into a private class dictionary, so only one of each
    56 // different kind of Type exists.  Types are never modified after creation, so
    57 // all their interesting fields are constant.
    58 class Type {
    59 public:
    60   enum TYPES {
    61     Bad=0,                      // Type check
    62     Control,                    // Control of code (not in lattice)
    63     Top,                        // Top of the lattice
    64     Int,                        // Integer range (lo-hi)
    65     Long,                       // Long integer range (lo-hi)
    66     Half,                       // Placeholder half of doubleword
    68     Tuple,                      // Method signature or object layout
    69     Array,                      // Array types
    71     AnyPtr,                     // Any old raw, klass, inst, or array pointer
    72     RawPtr,                     // Raw (non-oop) pointers
    73     OopPtr,                     // Any and all Java heap entities
    74     InstPtr,                    // Instance pointers (non-array objects)
    75     AryPtr,                     // Array pointers
    76     KlassPtr,                   // Klass pointers
    77     // (Ptr order matters:  See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
    79     Function,                   // Function signature
    80     Abio,                       // Abstract I/O
    81     Return_Address,             // Subroutine return address
    82     Memory,                     // Abstract store
    83     FloatTop,                   // No float value
    84     FloatCon,                   // Floating point constant
    85     FloatBot,                   // Any float value
    86     DoubleTop,                  // No double value
    87     DoubleCon,                  // Double precision constant
    88     DoubleBot,                  // Any double value
    89     Bottom,                     // Bottom of lattice
    90     lastype                     // Bogus ending type (not in lattice)
    91   };
    93   // Signal values for offsets from a base pointer
    94   enum OFFSET_SIGNALS {
    95     OffsetTop = -2000000000,    // undefined offset
    96     OffsetBot = -2000000001     // any possible offset
    97   };
    99   // Min and max WIDEN values.
   100   enum WIDEN {
   101     WidenMin = 0,
   102     WidenMax = 3
   103   };
   105 private:
   106   // Dictionary of types shared among compilations.
   107   static Dict* _shared_type_dict;
   109   static int uhash( const Type *const t );
   110   // Structural equality check.  Assumes that cmp() has already compared
   111   // the _base types and thus knows it can cast 't' appropriately.
   112   virtual bool eq( const Type *t ) const;
   114   // Top-level hash-table of types
   115   static Dict *type_dict() {
   116     return Compile::current()->type_dict();
   117   }
   119   // DUAL operation: reflect around lattice centerline.  Used instead of
   120   // join to ensure my lattice is symmetric up and down.  Dual is computed
   121   // lazily, on demand, and cached in _dual.
   122   const Type *_dual;            // Cached dual value
   123   // Table for efficient dualing of base types
   124   static const TYPES dual_type[lastype];
   126 protected:
   127   // Each class of type is also identified by its base.
   128   const TYPES _base;            // Enum of Types type
   130   Type( TYPES t ) : _dual(NULL),  _base(t) {} // Simple types
   131   // ~Type();                   // Use fast deallocation
   132   const Type *hashcons();       // Hash-cons the type
   134 public:
   136   inline void* operator new( size_t x ) {
   137     Compile* compile = Compile::current();
   138     compile->set_type_last_size(x);
   139     void *temp = compile->type_arena()->Amalloc_D(x);
   140     compile->set_type_hwm(temp);
   141     return temp;
   142   }
   143   inline void operator delete( void* ptr ) {
   144     Compile* compile = Compile::current();
   145     compile->type_arena()->Afree(ptr,compile->type_last_size());
   146   }
   148   // Initialize the type system for a particular compilation.
   149   static void Initialize(Compile* compile);
   151   // Initialize the types shared by all compilations.
   152   static void Initialize_shared(Compile* compile);
   154   TYPES base() const {
   155     assert(_base > Bad && _base < lastype, "sanity");
   156     return _base;
   157   }
   159   // Create a new hash-consd type
   160   static const Type *make(enum TYPES);
   161   // Test for equivalence of types
   162   static int cmp( const Type *const t1, const Type *const t2 );
   163   // Test for higher or equal in lattice
   164   int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
   166   // MEET operation; lower in lattice.
   167   const Type *meet( const Type *t ) const;
   168   // WIDEN: 'widens' for Ints and other range types
   169   virtual const Type *widen( const Type *old ) const { return this; }
   170   // NARROW: complement for widen, used by pessimistic phases
   171   virtual const Type *narrow( const Type *old ) const { return this; }
   173   // DUAL operation: reflect around lattice centerline.  Used instead of
   174   // join to ensure my lattice is symmetric up and down.
   175   const Type *dual() const { return _dual; }
   177   // Compute meet dependent on base type
   178   virtual const Type *xmeet( const Type *t ) const;
   179   virtual const Type *xdual() const;    // Compute dual right now.
   181   // JOIN operation; higher in lattice.  Done by finding the dual of the
   182   // meet of the dual of the 2 inputs.
   183   const Type *join( const Type *t ) const {
   184     return dual()->meet(t->dual())->dual(); }
   186   // Modified version of JOIN adapted to the needs Node::Value.
   187   // Normalizes all empty values to TOP.  Does not kill _widen bits.
   188   // Currently, it also works around limitations involving interface types.
   189   virtual const Type *filter( const Type *kills ) const;
   191   // Convenience access
   192   float getf() const;
   193   double getd() const;
   195   const TypeInt    *is_int() const;
   196   const TypeInt    *isa_int() const;             // Returns NULL if not an Int
   197   const TypeLong   *is_long() const;
   198   const TypeLong   *isa_long() const;            // Returns NULL if not a Long
   199   const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
   200   const TypeD      *isa_double_constant() const; // Returns NULL if not a DoubleCon
   201   const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
   202   const TypeF      *isa_float_constant() const;  // Returns NULL if not a FloatCon
   203   const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
   204   const TypeAry    *is_ary() const;              // Array, NOT array pointer
   205   const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
   206   const TypePtr    *isa_ptr() const;             // Returns NULL if not ptr type
   207   const TypeRawPtr *is_rawptr() const;           // NOT Java oop
   208   const TypeOopPtr *isa_oopptr() const;          // Returns NULL if not ptr type
   209   const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
   210   const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
   211   const TypeOopPtr  *is_oopptr() const;          // Java-style GC'd pointer
   212   const TypeInstPtr *isa_instptr() const;        // Returns NULL if not InstPtr
   213   const TypeInstPtr *is_instptr() const;         // Instance
   214   const TypeAryPtr *isa_aryptr() const;          // Returns NULL if not AryPtr
   215   const TypeAryPtr *is_aryptr() const;           // Array oop
   216   virtual bool      is_finite() const;           // Has a finite value
   217   virtual bool      is_nan()    const;           // Is not a number (NaN)
   219   // Special test for register pressure heuristic
   220   bool is_floatingpoint() const;        // True if Float or Double base type
   222   // Do you have memory, directly or through a tuple?
   223   bool has_memory( ) const;
   225   // Are you a pointer type or not?
   226   bool isa_oop_ptr() const;
   228   // TRUE if type is a singleton
   229   virtual bool singleton(void) const;
   231   // TRUE if type is above the lattice centerline, and is therefore vacuous
   232   virtual bool empty(void) const;
   234   // Return a hash for this type.  The hash function is public so ConNode
   235   // (constants) can hash on their constant, which is represented by a Type.
   236   virtual int hash() const;
   238   // Map ideal registers (machine types) to ideal types
   239   static const Type *mreg2type[];
   241   // Printing, statistics
   242   static const char * const msg[lastype]; // Printable strings
   243 #ifndef PRODUCT
   244   void         dump_on(outputStream *st) const;
   245   void         dump() const {
   246     dump_on(tty);
   247   }
   248   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   249   static  void dump_stats();
   250   static  void verify_lastype();          // Check that arrays match type enum
   251 #endif
   252   void typerr(const Type *t) const; // Mixing types error
   254   // Create basic type
   255   static const Type* get_const_basic_type(BasicType type) {
   256     assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
   257     return _const_basic_type[type];
   258   }
   260   // Mapping to the array element's basic type.
   261   BasicType array_element_basic_type() const;
   263   // Create standard type for a ciType:
   264   static const Type* get_const_type(ciType* type);
   266   // Create standard zero value:
   267   static const Type* get_zero_type(BasicType type) {
   268     assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
   269     return _zero_type[type];
   270   }
   272   // Report if this is a zero value (not top).
   273   bool is_zero_type() const {
   274     BasicType type = basic_type();
   275     if (type == T_VOID || type >= T_CONFLICT)
   276       return false;
   277     else
   278       return (this == _zero_type[type]);
   279   }
   281   // Convenience common pre-built types.
   282   static const Type *ABIO;
   283   static const Type *BOTTOM;
   284   static const Type *CONTROL;
   285   static const Type *DOUBLE;
   286   static const Type *FLOAT;
   287   static const Type *HALF;
   288   static const Type *MEMORY;
   289   static const Type *MULTI;
   290   static const Type *RETURN_ADDRESS;
   291   static const Type *TOP;
   293   // Mapping from compiler type to VM BasicType
   294   BasicType basic_type() const { return _basic_type[_base]; }
   296   // Mapping from CI type system to compiler type:
   297   static const Type* get_typeflow_type(ciType* type);
   299 private:
   300   // support arrays
   301   static const BasicType _basic_type[];
   302   static const Type*        _zero_type[T_CONFLICT+1];
   303   static const Type* _const_basic_type[T_CONFLICT+1];
   304 };
   306 //------------------------------TypeF------------------------------------------
   307 // Class of Float-Constant Types.
   308 class TypeF : public Type {
   309   TypeF( float f ) : Type(FloatCon), _f(f) {};
   310 public:
   311   virtual bool eq( const Type *t ) const;
   312   virtual int  hash() const;             // Type specific hashing
   313   virtual bool singleton(void) const;    // TRUE if type is a singleton
   314   virtual bool empty(void) const;        // TRUE if type is vacuous
   315 public:
   316   const float _f;               // Float constant
   318   static const TypeF *make(float f);
   320   virtual bool        is_finite() const;  // Has a finite value
   321   virtual bool        is_nan()    const;  // Is not a number (NaN)
   323   virtual const Type *xmeet( const Type *t ) const;
   324   virtual const Type *xdual() const;    // Compute dual right now.
   325   // Convenience common pre-built types.
   326   static const TypeF *ZERO; // positive zero only
   327   static const TypeF *ONE;
   328 #ifndef PRODUCT
   329   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   330 #endif
   331 };
   333 //------------------------------TypeD------------------------------------------
   334 // Class of Double-Constant Types.
   335 class TypeD : public Type {
   336   TypeD( double d ) : Type(DoubleCon), _d(d) {};
   337 public:
   338   virtual bool eq( const Type *t ) const;
   339   virtual int  hash() const;             // Type specific hashing
   340   virtual bool singleton(void) const;    // TRUE if type is a singleton
   341   virtual bool empty(void) const;        // TRUE if type is vacuous
   342 public:
   343   const double _d;              // Double constant
   345   static const TypeD *make(double d);
   347   virtual bool        is_finite() const;  // Has a finite value
   348   virtual bool        is_nan()    const;  // Is not a number (NaN)
   350   virtual const Type *xmeet( const Type *t ) const;
   351   virtual const Type *xdual() const;    // Compute dual right now.
   352   // Convenience common pre-built types.
   353   static const TypeD *ZERO; // positive zero only
   354   static const TypeD *ONE;
   355 #ifndef PRODUCT
   356   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   357 #endif
   358 };
   360 //------------------------------TypeInt----------------------------------------
   361 // Class of integer ranges, the set of integers between a lower bound and an
   362 // upper bound, inclusive.
   363 class TypeInt : public Type {
   364   TypeInt( jint lo, jint hi, int w );
   365 public:
   366   virtual bool eq( const Type *t ) const;
   367   virtual int  hash() const;             // Type specific hashing
   368   virtual bool singleton(void) const;    // TRUE if type is a singleton
   369   virtual bool empty(void) const;        // TRUE if type is vacuous
   370 public:
   371   const jint _lo, _hi;          // Lower bound, upper bound
   372   const short _widen;           // Limit on times we widen this sucker
   374   static const TypeInt *make(jint lo);
   375   // must always specify w
   376   static const TypeInt *make(jint lo, jint hi, int w);
   378   // Check for single integer
   379   int is_con() const { return _lo==_hi; }
   380   bool is_con(int i) const { return is_con() && _lo == i; }
   381   jint get_con() const { assert( is_con(), "" );  return _lo; }
   383   virtual bool        is_finite() const;  // Has a finite value
   385   virtual const Type *xmeet( const Type *t ) const;
   386   virtual const Type *xdual() const;    // Compute dual right now.
   387   virtual const Type *widen( const Type *t ) const;
   388   virtual const Type *narrow( const Type *t ) const;
   389   // Do not kill _widen bits.
   390   virtual const Type *filter( const Type *kills ) const;
   391   // Convenience common pre-built types.
   392   static const TypeInt *MINUS_1;
   393   static const TypeInt *ZERO;
   394   static const TypeInt *ONE;
   395   static const TypeInt *BOOL;
   396   static const TypeInt *CC;
   397   static const TypeInt *CC_LT;  // [-1]  == MINUS_1
   398   static const TypeInt *CC_GT;  // [1]   == ONE
   399   static const TypeInt *CC_EQ;  // [0]   == ZERO
   400   static const TypeInt *CC_LE;  // [-1,0]
   401   static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
   402   static const TypeInt *BYTE;
   403   static const TypeInt *CHAR;
   404   static const TypeInt *SHORT;
   405   static const TypeInt *POS;
   406   static const TypeInt *POS1;
   407   static const TypeInt *INT;
   408   static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
   409 #ifndef PRODUCT
   410   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   411 #endif
   412 };
   415 //------------------------------TypeLong---------------------------------------
   416 // Class of long integer ranges, the set of integers between a lower bound and
   417 // an upper bound, inclusive.
   418 class TypeLong : public Type {
   419   TypeLong( jlong lo, jlong hi, int w );
   420 public:
   421   virtual bool eq( const Type *t ) const;
   422   virtual int  hash() const;             // Type specific hashing
   423   virtual bool singleton(void) const;    // TRUE if type is a singleton
   424   virtual bool empty(void) const;        // TRUE if type is vacuous
   425 public:
   426   const jlong _lo, _hi;         // Lower bound, upper bound
   427   const short _widen;           // Limit on times we widen this sucker
   429   static const TypeLong *make(jlong lo);
   430   // must always specify w
   431   static const TypeLong *make(jlong lo, jlong hi, int w);
   433   // Check for single integer
   434   int is_con() const { return _lo==_hi; }
   435   jlong get_con() const { assert( is_con(), "" ); return _lo; }
   437   virtual bool        is_finite() const;  // Has a finite value
   439   virtual const Type *xmeet( const Type *t ) const;
   440   virtual const Type *xdual() const;    // Compute dual right now.
   441   virtual const Type *widen( const Type *t ) const;
   442   virtual const Type *narrow( const Type *t ) const;
   443   // Do not kill _widen bits.
   444   virtual const Type *filter( const Type *kills ) const;
   445   // Convenience common pre-built types.
   446   static const TypeLong *MINUS_1;
   447   static const TypeLong *ZERO;
   448   static const TypeLong *ONE;
   449   static const TypeLong *POS;
   450   static const TypeLong *LONG;
   451   static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
   452   static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
   453 #ifndef PRODUCT
   454   virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
   455 #endif
   456 };
   458 //------------------------------TypeTuple--------------------------------------
   459 // Class of Tuple Types, essentially type collections for function signatures
   460 // and class layouts.  It happens to also be a fast cache for the HotSpot
   461 // signature types.
   462 class TypeTuple : public Type {
   463   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
   464 public:
   465   virtual bool eq( const Type *t ) const;
   466   virtual int  hash() const;             // Type specific hashing
   467   virtual bool singleton(void) const;    // TRUE if type is a singleton
   468   virtual bool empty(void) const;        // TRUE if type is vacuous
   470 public:
   471   const uint          _cnt;              // Count of fields
   472   const Type ** const _fields;           // Array of field types
   474   // Accessors:
   475   uint cnt() const { return _cnt; }
   476   const Type* field_at(uint i) const {
   477     assert(i < _cnt, "oob");
   478     return _fields[i];
   479   }
   480   void set_field_at(uint i, const Type* t) {
   481     assert(i < _cnt, "oob");
   482     _fields[i] = t;
   483   }
   485   static const TypeTuple *make( uint cnt, const Type **fields );
   486   static const TypeTuple *make_range(ciSignature *sig);
   487   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
   489   // Subroutine call type with space allocated for argument types
   490   static const Type **fields( uint arg_cnt );
   492   virtual const Type *xmeet( const Type *t ) const;
   493   virtual const Type *xdual() const;    // Compute dual right now.
   494   // Convenience common pre-built types.
   495   static const TypeTuple *IFBOTH;
   496   static const TypeTuple *IFFALSE;
   497   static const TypeTuple *IFTRUE;
   498   static const TypeTuple *IFNEITHER;
   499   static const TypeTuple *LOOPBODY;
   500   static const TypeTuple *MEMBAR;
   501   static const TypeTuple *STORECONDITIONAL;
   502   static const TypeTuple *START_I2C;
   503   static const TypeTuple *INT_PAIR;
   504   static const TypeTuple *LONG_PAIR;
   505 #ifndef PRODUCT
   506   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
   507 #endif
   508 };
   510 //------------------------------TypeAry----------------------------------------
   511 // Class of Array Types
   512 class TypeAry : public Type {
   513   TypeAry( const Type *elem, const TypeInt *size) : Type(Array),
   514     _elem(elem), _size(size) {}
   515 public:
   516   virtual bool eq( const Type *t ) const;
   517   virtual int  hash() const;             // Type specific hashing
   518   virtual bool singleton(void) const;    // TRUE if type is a singleton
   519   virtual bool empty(void) const;        // TRUE if type is vacuous
   521 private:
   522   const Type *_elem;            // Element type of array
   523   const TypeInt *_size;         // Elements in array
   524   friend class TypeAryPtr;
   526 public:
   527   static const TypeAry *make(  const Type *elem, const TypeInt *size);
   529   virtual const Type *xmeet( const Type *t ) const;
   530   virtual const Type *xdual() const;    // Compute dual right now.
   531   bool ary_must_be_exact() const;  // true if arrays of such are never generic
   532 #ifndef PRODUCT
   533   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
   534 #endif
   535 };
   537 //------------------------------TypePtr----------------------------------------
   538 // Class of machine Pointer Types: raw data, instances or arrays.
   539 // If the _base enum is AnyPtr, then this refers to all of the above.
   540 // Otherwise the _base will indicate which subset of pointers is affected,
   541 // and the class will be inherited from.
   542 class TypePtr : public Type {
   543 public:
   544   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
   545 protected:
   546   TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
   547   virtual bool eq( const Type *t ) const;
   548   virtual int  hash() const;             // Type specific hashing
   549   static const PTR ptr_meet[lastPTR][lastPTR];
   550   static const PTR ptr_dual[lastPTR];
   551   static const char * const ptr_msg[lastPTR];
   553 public:
   554   const int _offset;            // Offset into oop, with TOP & BOT
   555   const PTR _ptr;               // Pointer equivalence class
   557   const int offset() const { return _offset; }
   558   const PTR ptr()    const { return _ptr; }
   560   static const TypePtr *make( TYPES t, PTR ptr, int offset );
   562   // Return a 'ptr' version of this type
   563   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   565   virtual intptr_t get_con() const;
   567   virtual const TypePtr *add_offset( int offset ) const;
   569   virtual bool singleton(void) const;    // TRUE if type is a singleton
   570   virtual bool empty(void) const;        // TRUE if type is vacuous
   571   virtual const Type *xmeet( const Type *t ) const;
   572   int meet_offset( int offset ) const;
   573   int dual_offset( ) const;
   574   virtual const Type *xdual() const;    // Compute dual right now.
   576   // meet, dual and join over pointer equivalence sets
   577   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
   578   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
   580   // This is textually confusing unless one recalls that
   581   // join(t) == dual()->meet(t->dual())->dual().
   582   PTR join_ptr( const PTR in_ptr ) const {
   583     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
   584   }
   586   // Tests for relation to centerline of type lattice:
   587   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
   588   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
   589   // Convenience common pre-built types.
   590   static const TypePtr *NULL_PTR;
   591   static const TypePtr *NOTNULL;
   592   static const TypePtr *BOTTOM;
   593 #ifndef PRODUCT
   594   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
   595 #endif
   596 };
   598 //------------------------------TypeRawPtr-------------------------------------
   599 // Class of raw pointers, pointers to things other than Oops.  Examples
   600 // include the stack pointer, top of heap, card-marking area, handles, etc.
   601 class TypeRawPtr : public TypePtr {
   602 protected:
   603   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
   604 public:
   605   virtual bool eq( const Type *t ) const;
   606   virtual int  hash() const;     // Type specific hashing
   608   const address _bits;          // Constant value, if applicable
   610   static const TypeRawPtr *make( PTR ptr );
   611   static const TypeRawPtr *make( address bits );
   613   // Return a 'ptr' version of this type
   614   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   616   virtual intptr_t get_con() const;
   618   virtual const TypePtr *add_offset( int offset ) const;
   620   virtual const Type *xmeet( const Type *t ) const;
   621   virtual const Type *xdual() const;    // Compute dual right now.
   622   // Convenience common pre-built types.
   623   static const TypeRawPtr *BOTTOM;
   624   static const TypeRawPtr *NOTNULL;
   625 #ifndef PRODUCT
   626   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
   627 #endif
   628 };
   630 //------------------------------TypeOopPtr-------------------------------------
   631 // Some kind of oop (Java pointer), either klass or instance or array.
   632 class TypeOopPtr : public TypePtr {
   633 protected:
   634   TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ) : TypePtr(t, ptr, offset), _const_oop(o), _klass(k), _klass_is_exact(xk), _instance_id(instance_id) { }
   635 public:
   636   virtual bool eq( const Type *t ) const;
   637   virtual int  hash() const;             // Type specific hashing
   638   virtual bool singleton(void) const;    // TRUE if type is a singleton
   639   enum {
   640    UNKNOWN_INSTANCE = 0
   641   };
   642 protected:
   644   int xadd_offset( int offset ) const;
   645   // Oop is NULL, unless this is a constant oop.
   646   ciObject*     _const_oop;   // Constant oop
   647   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
   648   ciKlass*      _klass;       // Klass object
   649   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
   650   bool          _klass_is_exact;
   652   int          _instance_id;   // if not UNKNOWN_INSTANCE, indicates that this is a particular instance
   653                                // of this type which is distinct.  This is the  the node index of the
   654                                // node creating this instance
   656   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
   658   int dual_instance()      const { return -_instance_id; }
   659   int meet_instance(int uid) const;
   661 public:
   662   // Creates a type given a klass. Correctly handles multi-dimensional arrays
   663   // Respects UseUniqueSubclasses.
   664   // If the klass is final, the resulting type will be exact.
   665   static const TypeOopPtr* make_from_klass(ciKlass* klass) {
   666     return make_from_klass_common(klass, true, false);
   667   }
   668   // Same as before, but will produce an exact type, even if
   669   // the klass is not final, as long as it has exactly one implementation.
   670   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
   671     return make_from_klass_common(klass, true, true);
   672   }
   673   // Same as before, but does not respects UseUniqueSubclasses.
   674   // Use this only for creating array element types.
   675   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
   676     return make_from_klass_common(klass, false, false);
   677   }
   678   // Creates a singleton type given an object.
   679   static const TypeOopPtr* make_from_constant(ciObject* o);
   681   // Make a generic (unclassed) pointer to an oop.
   682   static const TypeOopPtr* make(PTR ptr, int offset);
   684   ciObject* const_oop()    const { return _const_oop; }
   685   virtual ciKlass* klass() const { return _klass;     }
   686   bool klass_is_exact()    const { return _klass_is_exact; }
   687   bool is_instance()       const { return _instance_id != UNKNOWN_INSTANCE; }
   688   uint instance_id()       const { return _instance_id; }
   690   virtual intptr_t get_con() const;
   692   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   694   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
   696   virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
   698   // corresponding pointer to klass, for a given instance
   699   const TypeKlassPtr* as_klass_type() const;
   701   virtual const TypePtr *add_offset( int offset ) const;
   703   virtual const Type *xmeet( const Type *t ) const;
   704   virtual const Type *xdual() const;    // Compute dual right now.
   706   // Do not allow interface-vs.-noninterface joins to collapse to top.
   707   virtual const Type *filter( const Type *kills ) const;
   709   // Convenience common pre-built type.
   710   static const TypeOopPtr *BOTTOM;
   711 #ifndef PRODUCT
   712   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
   713 #endif
   714 };
   716 //------------------------------TypeInstPtr------------------------------------
   717 // Class of Java object pointers, pointing either to non-array Java instances
   718 // or to a klassOop (including array klasses).
   719 class TypeInstPtr : public TypeOopPtr {
   720   TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
   721   virtual bool eq( const Type *t ) const;
   722   virtual int  hash() const;             // Type specific hashing
   724   ciSymbol*  _name;        // class name
   726  public:
   727   ciSymbol* name()         const { return _name; }
   729   bool  is_loaded() const { return _klass->is_loaded(); }
   731   // Make a pointer to a constant oop.
   732   static const TypeInstPtr *make(ciObject* o) {
   733     return make(TypePtr::Constant, o->klass(), true, o, 0);
   734   }
   736   // Make a pointer to a constant oop with offset.
   737   static const TypeInstPtr *make(ciObject* o, int offset) {
   738     return make(TypePtr::Constant, o->klass(), true, o, offset);
   739   }
   741   // Make a pointer to some value of type klass.
   742   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
   743     return make(ptr, klass, false, NULL, 0);
   744   }
   746   // Make a pointer to some non-polymorphic value of exactly type klass.
   747   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
   748     return make(ptr, klass, true, NULL, 0);
   749   }
   751   // Make a pointer to some value of type klass with offset.
   752   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
   753     return make(ptr, klass, false, NULL, offset);
   754   }
   756   // Make a pointer to an oop.
   757   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = 0 );
   759   // If this is a java.lang.Class constant, return the type for it or NULL.
   760   // Pass to Type::get_const_type to turn it to a type, which will usually
   761   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
   762   ciType* java_mirror_type() const;
   764   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   766   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
   768   virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
   770   virtual const TypePtr *add_offset( int offset ) const;
   772   virtual const Type *xmeet( const Type *t ) const;
   773   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
   774   virtual const Type *xdual() const;    // Compute dual right now.
   776   // Convenience common pre-built types.
   777   static const TypeInstPtr *NOTNULL;
   778   static const TypeInstPtr *BOTTOM;
   779   static const TypeInstPtr *MIRROR;
   780   static const TypeInstPtr *MARK;
   781   static const TypeInstPtr *KLASS;
   782 #ifndef PRODUCT
   783   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
   784 #endif
   785 };
   787 //------------------------------TypeAryPtr-------------------------------------
   788 // Class of Java array pointers
   789 class TypeAryPtr : public TypeOopPtr {
   790   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), _ary(ary) {};
   791   virtual bool eq( const Type *t ) const;
   792   virtual int hash() const;     // Type specific hashing
   793   const TypeAry *_ary;          // Array we point into
   795 public:
   796   // Accessors
   797   ciKlass* klass() const;
   798   const TypeAry* ary() const  { return _ary; }
   799   const Type*    elem() const { return _ary->_elem; }
   800   const TypeInt* size() const { return _ary->_size; }
   802   static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = 0);
   803   // Constant pointer to array
   804   static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = 0);
   806   // Convenience
   807   static const TypeAryPtr *make(ciObject* o);
   809   // Return a 'ptr' version of this type
   810   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   812   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
   814   virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
   816   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
   818   virtual bool empty(void) const;        // TRUE if type is vacuous
   819   virtual const TypePtr *add_offset( int offset ) const;
   821   virtual const Type *xmeet( const Type *t ) const;
   822   virtual const Type *xdual() const;    // Compute dual right now.
   824   // Convenience common pre-built types.
   825   static const TypeAryPtr *RANGE;
   826   static const TypeAryPtr *OOPS;
   827   static const TypeAryPtr *BYTES;
   828   static const TypeAryPtr *SHORTS;
   829   static const TypeAryPtr *CHARS;
   830   static const TypeAryPtr *INTS;
   831   static const TypeAryPtr *LONGS;
   832   static const TypeAryPtr *FLOATS;
   833   static const TypeAryPtr *DOUBLES;
   834   // selects one of the above:
   835   static const TypeAryPtr *get_array_body_type(BasicType elem) {
   836     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
   837     return _array_body_type[elem];
   838   }
   839   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
   840   // sharpen the type of an int which is used as an array size
   841   static const TypeInt* narrow_size_type(const TypeInt* size, BasicType elem);
   842 #ifndef PRODUCT
   843   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
   844 #endif
   845 };
   847 //------------------------------TypeKlassPtr-----------------------------------
   848 // Class of Java Klass pointers
   849 class TypeKlassPtr : public TypeOopPtr {
   850   TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
   852   virtual bool eq( const Type *t ) const;
   853   virtual int hash() const;             // Type specific hashing
   855 public:
   856   ciSymbol* name()  const { return _klass->name(); }
   858   // ptr to klass 'k'
   859   static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
   860   // ptr to klass 'k' with offset
   861   static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
   862   // ptr to klass 'k' or sub-klass
   863   static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
   865   virtual const Type *cast_to_ptr_type(PTR ptr) const;
   867   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
   869   // corresponding pointer to instance, for a given class
   870   const TypeOopPtr* as_instance_type() const;
   872   virtual const TypePtr *add_offset( int offset ) const;
   873   virtual const Type    *xmeet( const Type *t ) const;
   874   virtual const Type    *xdual() const;      // Compute dual right now.
   876   // Convenience common pre-built types.
   877   static const TypeKlassPtr* OBJECT; // Not-null object klass or below
   878   static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
   879 #ifndef PRODUCT
   880   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
   881 #endif
   882 };
   884 //------------------------------TypeFunc---------------------------------------
   885 // Class of Array Types
   886 class TypeFunc : public Type {
   887   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}
   888   virtual bool eq( const Type *t ) const;
   889   virtual int  hash() const;             // Type specific hashing
   890   virtual bool singleton(void) const;    // TRUE if type is a singleton
   891   virtual bool empty(void) const;        // TRUE if type is vacuous
   892 public:
   893   // Constants are shared among ADLC and VM
   894   enum { Control    = AdlcVMDeps::Control,
   895          I_O        = AdlcVMDeps::I_O,
   896          Memory     = AdlcVMDeps::Memory,
   897          FramePtr   = AdlcVMDeps::FramePtr,
   898          ReturnAdr  = AdlcVMDeps::ReturnAdr,
   899          Parms      = AdlcVMDeps::Parms
   900   };
   902   const TypeTuple* const _domain;     // Domain of inputs
   903   const TypeTuple* const _range;      // Range of results
   905   // Accessors:
   906   const TypeTuple* domain() const { return _domain; }
   907   const TypeTuple* range()  const { return _range; }
   909   static const TypeFunc *make(ciMethod* method);
   910   static const TypeFunc *make(ciSignature signature, const Type* extra);
   911   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
   913   virtual const Type *xmeet( const Type *t ) const;
   914   virtual const Type *xdual() const;    // Compute dual right now.
   916   BasicType return_type() const;
   918 #ifndef PRODUCT
   919   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
   920   void print_flattened() const; // Print a 'flattened' signature
   921 #endif
   922   // Convenience common pre-built types.
   923 };
   925 //------------------------------accessors--------------------------------------
   926 inline float Type::getf() const {
   927   assert( _base == FloatCon, "Not a FloatCon" );
   928   return ((TypeF*)this)->_f;
   929 }
   931 inline double Type::getd() const {
   932   assert( _base == DoubleCon, "Not a DoubleCon" );
   933   return ((TypeD*)this)->_d;
   934 }
   936 inline const TypeF *Type::is_float_constant() const {
   937   assert( _base == FloatCon, "Not a Float" );
   938   return (TypeF*)this;
   939 }
   941 inline const TypeF *Type::isa_float_constant() const {
   942   return ( _base == FloatCon ? (TypeF*)this : NULL);
   943 }
   945 inline const TypeD *Type::is_double_constant() const {
   946   assert( _base == DoubleCon, "Not a Double" );
   947   return (TypeD*)this;
   948 }
   950 inline const TypeD *Type::isa_double_constant() const {
   951   return ( _base == DoubleCon ? (TypeD*)this : NULL);
   952 }
   954 inline const TypeInt *Type::is_int() const {
   955   assert( _base == Int, "Not an Int" );
   956   return (TypeInt*)this;
   957 }
   959 inline const TypeInt *Type::isa_int() const {
   960   return ( _base == Int ? (TypeInt*)this : NULL);
   961 }
   963 inline const TypeLong *Type::is_long() const {
   964   assert( _base == Long, "Not a Long" );
   965   return (TypeLong*)this;
   966 }
   968 inline const TypeLong *Type::isa_long() const {
   969   return ( _base == Long ? (TypeLong*)this : NULL);
   970 }
   972 inline const TypeTuple *Type::is_tuple() const {
   973   assert( _base == Tuple, "Not a Tuple" );
   974   return (TypeTuple*)this;
   975 }
   977 inline const TypeAry *Type::is_ary() const {
   978   assert( _base == Array , "Not an Array" );
   979   return (TypeAry*)this;
   980 }
   982 inline const TypePtr *Type::is_ptr() const {
   983   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
   984   assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
   985   return (TypePtr*)this;
   986 }
   988 inline const TypePtr *Type::isa_ptr() const {
   989   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
   990   return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
   991 }
   993 inline const TypeOopPtr *Type::is_oopptr() const {
   994   // OopPtr is the first and KlassPtr the last, with no non-oops between.
   995   assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
   996   return (TypeOopPtr*)this;
   997 }
   999 inline const TypeOopPtr *Type::isa_oopptr() const {
  1000   // OopPtr is the first and KlassPtr the last, with no non-oops between.
  1001   return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
  1004 inline const TypeRawPtr *Type::is_rawptr() const {
  1005   assert( _base == RawPtr, "Not a raw pointer" );
  1006   return (TypeRawPtr*)this;
  1009 inline const TypeInstPtr *Type::isa_instptr() const {
  1010   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
  1013 inline const TypeInstPtr *Type::is_instptr() const {
  1014   assert( _base == InstPtr, "Not an object pointer" );
  1015   return (TypeInstPtr*)this;
  1018 inline const TypeAryPtr *Type::isa_aryptr() const {
  1019   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
  1022 inline const TypeAryPtr *Type::is_aryptr() const {
  1023   assert( _base == AryPtr, "Not an array pointer" );
  1024   return (TypeAryPtr*)this;
  1027 inline const TypeKlassPtr *Type::isa_klassptr() const {
  1028   return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
  1031 inline const TypeKlassPtr *Type::is_klassptr() const {
  1032   assert( _base == KlassPtr, "Not a klass pointer" );
  1033   return (TypeKlassPtr*)this;
  1036 inline bool Type::is_floatingpoint() const {
  1037   if( (_base == FloatCon)  || (_base == FloatBot) ||
  1038       (_base == DoubleCon) || (_base == DoubleBot) )
  1039     return true;
  1040   return false;
  1044 // ===============================================================
  1045 // Things that need to be 64-bits in the 64-bit build but
  1046 // 32-bits in the 32-bit build.  Done this way to get full
  1047 // optimization AND strong typing.
  1048 #ifdef _LP64
  1050 // For type queries and asserts
  1051 #define is_intptr_t  is_long
  1052 #define isa_intptr_t isa_long
  1053 #define find_intptr_t_type find_long_type
  1054 #define find_intptr_t_con  find_long_con
  1055 #define TypeX        TypeLong
  1056 #define Type_X       Type::Long
  1057 #define TypeX_X      TypeLong::LONG
  1058 #define TypeX_ZERO   TypeLong::ZERO
  1059 // For 'ideal_reg' machine registers
  1060 #define Op_RegX      Op_RegL
  1061 // For phase->intcon variants
  1062 #define MakeConX     longcon
  1063 #define ConXNode     ConLNode
  1064 // For array index arithmetic
  1065 #define MulXNode     MulLNode
  1066 #define AndXNode     AndLNode
  1067 #define OrXNode      OrLNode
  1068 #define CmpXNode     CmpLNode
  1069 #define SubXNode     SubLNode
  1070 #define LShiftXNode  LShiftLNode
  1071 // For object size computation:
  1072 #define AddXNode     AddLNode
  1073 #define RShiftXNode  RShiftLNode
  1074 // For card marks and hashcodes
  1075 #define URShiftXNode URShiftLNode
  1076 // Opcodes
  1077 #define Op_LShiftX   Op_LShiftL
  1078 #define Op_AndX      Op_AndL
  1079 #define Op_AddX      Op_AddL
  1080 #define Op_SubX      Op_SubL
  1081 // conversions
  1082 #define ConvI2X(x)   ConvI2L(x)
  1083 #define ConvL2X(x)   (x)
  1084 #define ConvX2I(x)   ConvL2I(x)
  1085 #define ConvX2L(x)   (x)
  1087 #else
  1089 // For type queries and asserts
  1090 #define is_intptr_t  is_int
  1091 #define isa_intptr_t isa_int
  1092 #define find_intptr_t_type find_int_type
  1093 #define find_intptr_t_con  find_int_con
  1094 #define TypeX        TypeInt
  1095 #define Type_X       Type::Int
  1096 #define TypeX_X      TypeInt::INT
  1097 #define TypeX_ZERO   TypeInt::ZERO
  1098 // For 'ideal_reg' machine registers
  1099 #define Op_RegX      Op_RegI
  1100 // For phase->intcon variants
  1101 #define MakeConX     intcon
  1102 #define ConXNode     ConINode
  1103 // For array index arithmetic
  1104 #define MulXNode     MulINode
  1105 #define AndXNode     AndINode
  1106 #define OrXNode      OrINode
  1107 #define CmpXNode     CmpINode
  1108 #define SubXNode     SubINode
  1109 #define LShiftXNode  LShiftINode
  1110 // For object size computation:
  1111 #define AddXNode     AddINode
  1112 #define RShiftXNode  RShiftINode
  1113 // For card marks and hashcodes
  1114 #define URShiftXNode URShiftINode
  1115 // Opcodes
  1116 #define Op_LShiftX   Op_LShiftI
  1117 #define Op_AndX      Op_AndI
  1118 #define Op_AddX      Op_AddI
  1119 #define Op_SubX      Op_SubI
  1120 // conversions
  1121 #define ConvI2X(x)   (x)
  1122 #define ConvL2X(x)   ConvL2I(x)
  1123 #define ConvX2I(x)   (x)
  1124 #define ConvX2L(x)   ConvI2L(x)
  1126 #endif

mercurial